diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-09 20:16:55 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-09 20:16:55 +0000 |
commit | 808d103da058975e8aebe257ec6479a42d92cda4 (patch) | |
tree | e6c070f6a5f4210a5a840e80e15e936d56126935 | |
parent | 0e3c9572844ac820dc2f83ce6f6985afc836369b (diff) | |
download | chromium_src-808d103da058975e8aebe257ec6479a42d92cda4.zip chromium_src-808d103da058975e8aebe257ec6479a42d92cda4.tar.gz chromium_src-808d103da058975e8aebe257ec6479a42d92cda4.tar.bz2 |
Cleanup more test code.
BUG=none
TEST=compiles
Review URL: http://codereview.chromium.org/6462015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74328 0039d316-1c4b-4281-b951-d872f2087c98
48 files changed, 1328 insertions, 775 deletions
diff --git a/chrome/browser/sessions/session_service_test_helper.cc b/chrome/browser/sessions/session_service_test_helper.cc index fda500b..5a87303 100644 --- a/chrome/browser/sessions/session_service_test_helper.cc +++ b/chrome/browser/sessions/session_service_test_helper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,6 +13,13 @@ using base::Time; +SessionServiceTestHelper::SessionServiceTestHelper() {} + +SessionServiceTestHelper::SessionServiceTestHelper(SessionService* service) + : service_(service) {} + +SessionServiceTestHelper::~SessionServiceTestHelper() {} + void SessionServiceTestHelper::RestoreSessionFromCommands( const std::vector<SessionCommand*>& commands, std::vector<SessionWindow*>* valid_windows) { diff --git a/chrome/browser/sessions/session_service_test_helper.h b/chrome/browser/sessions/session_service_test_helper.h index 062bb1c..882a0b5 100644 --- a/chrome/browser/sessions/session_service_test_helper.h +++ b/chrome/browser/sessions/session_service_test_helper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -23,10 +23,9 @@ class TabNavigation; class SessionServiceTestHelper { public: - explicit SessionServiceTestHelper() {} - - explicit SessionServiceTestHelper(SessionService* service) - : service_(service) {} + explicit SessionServiceTestHelper(); + explicit SessionServiceTestHelper(SessionService* service); + ~SessionServiceTestHelper(); void RestoreSessionFromCommands(const std::vector<SessionCommand*>& commands, std::vector<SessionWindow*>* valid_windows); diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.cc b/chrome/browser/sync/abstract_profile_sync_service_test.cc index 26c9094..3c54e23 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.cc +++ b/chrome/browser/sync/abstract_profile_sync_service_test.cc @@ -1,4 +1,4 @@ -// Copyright (c) 20111 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -98,6 +98,8 @@ bool ProfileSyncServiceTestHelper::CreateRoot( AbstractProfileSyncServiceTest::AbstractProfileSyncServiceTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} +AbstractProfileSyncServiceTest::~AbstractProfileSyncServiceTest() {} + bool AbstractProfileSyncServiceTest::CreateRoot(ModelType model_type) { return ProfileSyncServiceTestHelper::CreateRoot( model_type, diff --git a/chrome/browser/sync/abstract_profile_sync_service_test.h b/chrome/browser/sync/abstract_profile_sync_service_test.h index 522af54..8e67378 100644 --- a/chrome/browser/sync/abstract_profile_sync_service_test.h +++ b/chrome/browser/sync/abstract_profile_sync_service_test.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -40,6 +40,7 @@ class ProfileSyncServiceTestHelper { class AbstractProfileSyncServiceTest : public testing::Test { public: AbstractProfileSyncServiceTest(); + virtual ~AbstractProfileSyncServiceTest(); bool CreateRoot(syncable::ModelType model_type); diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index ccce188..2b56187 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -86,12 +86,14 @@ 'browser/renderer_host/test/test_backing_store.h', 'browser/renderer_host/test/test_render_view_host.cc', 'browser/renderer_host/test/test_render_view_host.h', - 'browser/tab_contents/test_tab_contents.cc', - 'browser/tab_contents/test_tab_contents.h', + 'browser/sessions/session_service_test_helper.cc', + 'browser/sessions/session_service_test_helper.h', 'browser/sync/profile_sync_service_mock.cc', 'browser/sync/profile_sync_service_mock.h', 'browser/sync/syncable/syncable_mock.cc', 'browser/sync/syncable/syncable_mock.h', + 'browser/tab_contents/test_tab_contents.cc', + 'browser/tab_contents/test_tab_contents.h', 'browser/ui/browser.h', 'browser/ui/cocoa/browser_test_helper.h', 'browser/ui/tab_contents/test_tab_contents_wrapper.cc', @@ -1407,8 +1409,6 @@ 'browser/search_engines/template_url_scraper_unittest.cc', 'browser/search_engines/template_url_unittest.cc', 'browser/sessions/session_backend_unittest.cc', - 'browser/sessions/session_service_test_helper.cc', - 'browser/sessions/session_service_test_helper.h', 'browser/sessions/session_service_unittest.cc', 'browser/shell_integration_unittest.cc', 'browser/speech/endpointer/endpointer_unittest.cc', @@ -2915,13 +2915,13 @@ 'app/chrome_dll_version.rc.version', 'browser/password_manager/password_form_data.cc', 'browser/sessions/session_backend.cc', - 'browser/sessions/session_service_test_helper.cc', 'browser/sync/glue/session_model_associator.cc', 'test/bookmark_load_observer.h', 'test/out_of_proc_test_runner.cc', 'test/live_sync/bookmark_model_verifier.cc', 'test/live_sync/bookmark_model_verifier.h', 'test/live_sync/live_autofill_sync_test.h', + 'test/live_sync/live_bookmarks_sync_test.cc', 'test/live_sync/live_bookmarks_sync_test.h', 'test/live_sync/live_extensions_sync_test_base.cc', 'test/live_sync/live_extensions_sync_test_base.h', @@ -2929,6 +2929,7 @@ 'test/live_sync/live_extensions_sync_test.h', 'test/live_sync/live_passwords_sync_test.h', 'test/live_sync/live_preferences_sync_test.h', + 'test/live_sync/live_sessions_sync_test.cc', 'test/live_sync/live_sessions_sync_test.h', 'test/live_sync/live_themes_sync_test.cc', 'test/live_sync/live_themes_sync_test.h', diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.cc b/chrome/test/live_sync/live_bookmarks_sync_test.cc new file mode 100644 index 0000000..50faab4 --- /dev/null +++ b/chrome/test/live_sync/live_bookmarks_sync_test.cc @@ -0,0 +1,262 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_bookmarks_sync_test.h" + +#include "base/utf_string_conversions.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/test/ui_test_utils.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/codec/png_codec.h" + +LiveBookmarksSyncTest::LiveBookmarksSyncTest(TestType test_type) + : LiveSyncTest(test_type) {} + +LiveBookmarksSyncTest::~LiveBookmarksSyncTest() {} + +bool LiveBookmarksSyncTest::SetupClients() { + if (!LiveSyncTest::SetupClients()) + return false; + for (int i = 0; i < num_clients(); ++i) { + ui_test_utils::WaitForBookmarkModelToLoad( + GetProfile(i)->GetBookmarkModel()); + } + verifier_helper_.reset( + new BookmarkModelVerifier(GetVerifierBookmarkModel())); + ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel()); + return true; +} + +BookmarkModel* LiveBookmarksSyncTest::GetBookmarkModel(int index) { + return GetProfile(index)->GetBookmarkModel(); +} + +const BookmarkNode* LiveBookmarksSyncTest::GetBookmarkBarNode(int index) { + return GetBookmarkModel(index)->GetBookmarkBarNode(); +} + +const BookmarkNode* LiveBookmarksSyncTest::GetOtherNode(int index) { + return GetBookmarkModel(index)->other_node(); +} + +BookmarkModel* LiveBookmarksSyncTest::GetVerifierBookmarkModel() { + return verifier()->GetBookmarkModel(); +} + +void LiveBookmarksSyncTest::DisableVerifier() { + verifier_helper_->set_use_verifier_model(false); +} + +const BookmarkNode* LiveBookmarksSyncTest::AddURL(int profile, + const std::wstring& title, + const GURL& url) { + return verifier_helper_->AddURL(GetBookmarkModel(profile), + GetBookmarkBarNode(profile), + 0, WideToUTF16(title), url); +} + +const BookmarkNode* LiveBookmarksSyncTest::AddURL(int profile, + int index, + const std::wstring& title, + const GURL& url) { + return verifier_helper_->AddURL(GetBookmarkModel(profile), + GetBookmarkBarNode(profile), + index, WideToUTF16(title), url); +} + +const BookmarkNode* LiveBookmarksSyncTest::AddURL(int profile, + const BookmarkNode* parent, + int index, + const std::wstring& title, + const GURL& url) { + EXPECT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent); + return verifier_helper_->AddURL(GetBookmarkModel(profile), parent, index, + WideToUTF16(title), url); +} + +const BookmarkNode* LiveBookmarksSyncTest::AddGroup(int profile, + const std::wstring& title) { + return verifier_helper_->AddGroup(GetBookmarkModel(profile), + GetBookmarkBarNode(profile), + 0, WideToUTF16(title)); +} + +const BookmarkNode* LiveBookmarksSyncTest::AddGroup(int profile, + int index, + const std::wstring& title) { + return verifier_helper_->AddGroup(GetBookmarkModel(profile), + GetBookmarkBarNode(profile), + index, WideToUTF16(title)); +} + +const BookmarkNode* LiveBookmarksSyncTest::AddGroup(int profile, + const BookmarkNode* parent, + int index, + const std::wstring& title) { + if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { + LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " + << "Profile " << profile; + return NULL; + } + return verifier_helper_->AddGroup( + GetBookmarkModel(profile), parent, index, WideToUTF16(title)); +} + +void LiveBookmarksSyncTest::SetTitle(int profile, + const BookmarkNode* node, + const std::wstring& new_title) { + ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) + << "Node " << node->GetTitle() << " does not belong to " + << "Profile " << profile; + verifier_helper_->SetTitle( + GetBookmarkModel(profile), node, WideToUTF16(new_title)); +} + +void LiveBookmarksSyncTest::SetFavicon( + int profile, + const BookmarkNode* node, + const std::vector<unsigned char>& icon_bytes_vector) { + ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) + << "Node " << node->GetTitle() << " does not belong to " + << "Profile " << profile; + ASSERT_EQ(BookmarkNode::URL, node->type()) + << "Node " << node->GetTitle() << " must be a url."; + verifier_helper_->SetFavicon( + GetBookmarkModel(profile), node, icon_bytes_vector); +} + +const BookmarkNode* LiveBookmarksSyncTest::SetURL(int profile, + const BookmarkNode* node, + const GURL& new_url) { + if (GetBookmarkModel(profile)->GetNodeByID(node->id()) != node) { + LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " + << "Profile " << profile; + return NULL; + } + return verifier_helper_->SetURL(GetBookmarkModel(profile), node, new_url); +} + +void LiveBookmarksSyncTest::Move(int profile, + const BookmarkNode* node, + const BookmarkNode* new_parent, + int index) { + ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) + << "Node " << node->GetTitle() << " does not belong to " + << "Profile " << profile; + verifier_helper_->Move( + GetBookmarkModel(profile), node, new_parent, index); +} + + +void LiveBookmarksSyncTest::Remove(int profile, const BookmarkNode* parent, + int index) { + ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) + << "Node " << parent->GetTitle() << " does not belong to " + << "Profile " << profile; + verifier_helper_->Remove(GetBookmarkModel(profile), parent, index); +} + +void LiveBookmarksSyncTest::SortChildren(int profile, + const BookmarkNode* parent) { + ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) + << "Node " << parent->GetTitle() << " does not belong to " + << "Profile " << profile; + verifier_helper_->SortChildren(GetBookmarkModel(profile), parent); +} + +void LiveBookmarksSyncTest::ReverseChildOrder(int profile, + const BookmarkNode* parent) { + ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) + << "Node " << parent->GetTitle() << " does not belong to " + << "Profile " << profile; + verifier_helper_->ReverseChildOrder(GetBookmarkModel(profile), parent); +} + +bool LiveBookmarksSyncTest::ModelMatchesVerifier(int profile) { + if (verifier_helper_->use_verifier_model() == false) { + LOG(ERROR) << "Illegal to call ModelMatchesVerifier() after " + << "DisableVerifier(). Use ModelsMatch() instead."; + return false; + } + return BookmarkModelVerifier::ModelsMatch( + GetVerifierBookmarkModel(), GetBookmarkModel(profile)); +} + +bool LiveBookmarksSyncTest::AllModelsMatchVerifier() { + if (verifier_helper_->use_verifier_model() == false) { + LOG(ERROR) << "Illegal to call AllModelsMatchVerifier() after " + << "DisableVerifier(). Use AllModelsMatch() instead."; + return false; + } + for (int i = 0; i < num_clients(); ++i) { + if (!ModelMatchesVerifier(i)) { + LOG(ERROR) << "Model " << i << " does not match the verifier."; + return false; + } + } + return true; +} + +bool LiveBookmarksSyncTest::ModelsMatch(int profile_a, int profile_b) { + return BookmarkModelVerifier::ModelsMatch( + GetBookmarkModel(profile_a), GetBookmarkModel(profile_b)); +} + +bool LiveBookmarksSyncTest::AllModelsMatch() { + for (int i = 1; i < num_clients(); ++i) { + if (!ModelsMatch(0, i)) { + LOG(ERROR) << "Model " << i << " does not match Model 0."; + return false; + } + } + return true; +} + +bool LiveBookmarksSyncTest::ContainsDuplicateBookmarks(int profile) { + return BookmarkModelVerifier::ContainsDuplicateBookmarks( + GetBookmarkModel(profile)); +} + +const BookmarkNode* LiveBookmarksSyncTest::GetUniqueNodeByURL(int profile, + const GURL& url) { + std::vector<const BookmarkNode*> nodes; + GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); + EXPECT_EQ(1U, nodes.size()); + if (nodes.empty()) + return NULL; + return nodes[0]; +} + +int LiveBookmarksSyncTest::CountBookmarksWithTitlesMatching( + int profile, + const std::wstring& title) { + return verifier_helper_->CountNodesWithTitlesMatching( + GetBookmarkModel(profile), BookmarkNode::URL, WideToUTF16(title)); +} + +int LiveBookmarksSyncTest::CountFoldersWithTitlesMatching( + int profile, + const std::wstring& title) { + return verifier_helper_->CountNodesWithTitlesMatching( + GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title)); +} + +// static +std::vector<unsigned char> LiveBookmarksSyncTest::CreateFavicon(int seed) { + const int w = 16; + const int h = 16; + SkBitmap bmp; + bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h); + bmp.allocPixels(); + uint32_t* src_data = bmp.getAddr32(0, 0); + for (int i = 0; i < w * h; ++i) { + src_data[i] = SkPreMultiplyARGB((seed + i) % 255, + (seed + i) % 250, + (seed + i) % 245, + (seed + i) % 240); + } + std::vector<unsigned char> favicon; + gfx::PNGCodec::EncodeBGRASkBitmap(bmp, false, &favicon); + return favicon; +} diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.h b/chrome/test/live_sync/live_bookmarks_sync_test.h index 16ab5b5..9c20618 100644 --- a/chrome/test/live_sync/live_bookmarks_sync_test.h +++ b/chrome/test/live_sync/live_bookmarks_sync_test.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,68 +11,42 @@ #include "base/compiler_specific.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/test/live_sync/bookmark_model_verifier.h" #include "chrome/test/live_sync/live_sync_test.h" -#include "chrome/test/ui_test_utils.h" -#include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/gfx/codec/png_codec.h" + +class GURL; +class Profile; class LiveBookmarksSyncTest : public LiveSyncTest { public: - explicit LiveBookmarksSyncTest(TestType test_type) - : LiveSyncTest(test_type) {} - - virtual ~LiveBookmarksSyncTest() {} + explicit LiveBookmarksSyncTest(TestType test_type); + virtual ~LiveBookmarksSyncTest(); // Sets up sync profiles and clients and initializes the bookmark verifier. - virtual bool SetupClients() WARN_UNUSED_RESULT { - if (!LiveSyncTest::SetupClients()) - return false; - for (int i = 0; i < num_clients(); ++i) { - ui_test_utils::WaitForBookmarkModelToLoad( - GetProfile(i)->GetBookmarkModel()); - } - verifier_helper_.reset( - new BookmarkModelVerifier(GetVerifierBookmarkModel())); - ui_test_utils::WaitForBookmarkModelToLoad(verifier()->GetBookmarkModel()); - return true; - } + virtual bool SetupClients() WARN_UNUSED_RESULT; // Used to access the bookmark model within a particular sync profile. - BookmarkModel* GetBookmarkModel(int index) WARN_UNUSED_RESULT { - return GetProfile(index)->GetBookmarkModel(); - } + BookmarkModel* GetBookmarkModel(int index) WARN_UNUSED_RESULT; // Used to access the bookmark bar within a particular sync profile. - const BookmarkNode* GetBookmarkBarNode(int index) WARN_UNUSED_RESULT { - return GetBookmarkModel(index)->GetBookmarkBarNode(); - } + const BookmarkNode* GetBookmarkBarNode(int index) WARN_UNUSED_RESULT; // Used to access the "other bookmarks" node within a particular sync profile. - const BookmarkNode* GetOtherNode(int index) WARN_UNUSED_RESULT { - return GetBookmarkModel(index)->other_node(); - } + const BookmarkNode* GetOtherNode(int index) WARN_UNUSED_RESULT; // Used to access the bookmarks within the verifier sync profile. - BookmarkModel* GetVerifierBookmarkModel() WARN_UNUSED_RESULT { - return verifier()->GetBookmarkModel(); - } + BookmarkModel* GetVerifierBookmarkModel() WARN_UNUSED_RESULT; // After calling this method, changes made to a bookmark model will no longer // be reflected in the verifier model. - void DisableVerifier() { verifier_helper_->set_use_verifier_model(false); } + void DisableVerifier(); // Adds a URL with address |url| and title |title| to the bookmark bar of // profile |profile|. Returns a pointer to the node that was added. const BookmarkNode* AddURL(int profile, const std::wstring& title, - const GURL& url) WARN_UNUSED_RESULT { - return verifier_helper_->AddURL(GetBookmarkModel(profile), - GetBookmarkBarNode(profile), 0, WideToUTF16(title), url); - } + const GURL& url) WARN_UNUSED_RESULT; // Adds a URL with address |url| and title |title| to the bookmark bar of // profile |profile| at position |index|. Returns a pointer to the node that @@ -80,10 +54,7 @@ class LiveBookmarksSyncTest : public LiveSyncTest { const BookmarkNode* AddURL(int profile, int index, const std::wstring& title, - const GURL& url) WARN_UNUSED_RESULT { - return verifier_helper_->AddURL(GetBookmarkModel(profile), - GetBookmarkBarNode(profile), index, WideToUTF16(title), url); - } + const GURL& url) WARN_UNUSED_RESULT; // Adds a URL with address |url| and title |title| under the node |parent| of // profile |profile| at position |index|. Returns a pointer to the node that @@ -92,28 +63,18 @@ class LiveBookmarksSyncTest : public LiveSyncTest { const BookmarkNode* parent, int index, const std::wstring& title, - const GURL& url) WARN_UNUSED_RESULT { - EXPECT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent); - return verifier_helper_->AddURL(GetBookmarkModel(profile), parent, index, - WideToUTF16(title), url); - } + const GURL& url) WARN_UNUSED_RESULT; // Adds a group named |title| to the bookmark bar of profile |profile|. // Returns a pointer to the group that was added. const BookmarkNode* AddGroup(int profile, - const std::wstring& title) WARN_UNUSED_RESULT { - return verifier_helper_->AddGroup(GetBookmarkModel(profile), - GetBookmarkBarNode(profile), 0, WideToUTF16(title)); - } + const std::wstring& title) WARN_UNUSED_RESULT; // Adds a group named |title| to the bookmark bar of profile |profile| at // position |index|. Returns a pointer to the group that was added. const BookmarkNode* AddGroup(int profile, int index, - const std::wstring& title) WARN_UNUSED_RESULT { - return verifier_helper_->AddGroup(GetBookmarkModel(profile), - GetBookmarkBarNode(profile), index, WideToUTF16(title)); - } + const std::wstring& title) WARN_UNUSED_RESULT; // Adds a group named |title| to the node |parent| in the bookmark model of // profile |profile| at position |index|. Returns a pointer to the node that @@ -121,198 +82,85 @@ class LiveBookmarksSyncTest : public LiveSyncTest { const BookmarkNode* AddGroup(int profile, const BookmarkNode* parent, int index, - const std::wstring& title) WARN_UNUSED_RESULT { - if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { - LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " - << "Profile " << profile; - return NULL; - } - return verifier_helper_->AddGroup( - GetBookmarkModel(profile), parent, index, WideToUTF16(title)); - } + const std::wstring& title) WARN_UNUSED_RESULT; // Changes the title of the node |node| in the bookmark model of profile // |profile| to |new_title|. void SetTitle(int profile, const BookmarkNode* node, - const std::wstring& new_title) { - ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) - << "Node " << node->GetTitle() << " does not belong to " - << "Profile " << profile; - verifier_helper_->SetTitle( - GetBookmarkModel(profile), node, WideToUTF16(new_title)); - } + const std::wstring& new_title); // Sets the favicon of the node |node| (of type BookmarkNode::URL) in the // bookmark model of profile |profile| using the data in |icon_bytes_vector|. void SetFavicon(int profile, const BookmarkNode* node, - const std::vector<unsigned char>& icon_bytes_vector) { - ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) - << "Node " << node->GetTitle() << " does not belong to " - << "Profile " << profile; - ASSERT_EQ(BookmarkNode::URL, node->type()) - << "Node " << node->GetTitle() << " must be a url."; - verifier_helper_->SetFavicon( - GetBookmarkModel(profile), node, icon_bytes_vector); - } + const std::vector<unsigned char>& icon_bytes_vector); // Changes the url of the node |node| in the bookmark model of profile // |profile| to |new_url|. Returns a pointer to the node with the changed url. const BookmarkNode* SetURL(int profile, const BookmarkNode* node, - const GURL& new_url) WARN_UNUSED_RESULT { - if (GetBookmarkModel(profile)->GetNodeByID(node->id()) != node) { - LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " - << "Profile " << profile; - return NULL; - } - return verifier_helper_->SetURL(GetBookmarkModel(profile), node, new_url); - } + const GURL& new_url) WARN_UNUSED_RESULT; // Moves the node |node| in the bookmark model of profile |profile| so it ends // up under the node |new_parent| at position |index|. void Move(int profile, const BookmarkNode* node, const BookmarkNode* new_parent, - int index) { - ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) - << "Node " << node->GetTitle() << " does not belong to " - << "Profile " << profile; - verifier_helper_->Move( - GetBookmarkModel(profile), node, new_parent, index); - } + int index); // Removes the node in the bookmark model of profile |profile| under the node // |parent| at position |index|. - void Remove(int profile, const BookmarkNode* parent, int index) { - ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) - << "Node " << parent->GetTitle() << " does not belong to " - << "Profile " << profile; - verifier_helper_->Remove(GetBookmarkModel(profile), parent, index); - } + void Remove(int profile, const BookmarkNode* parent, int index); // Sorts the children of the node |parent| in the bookmark model of profile // |profile|. - void SortChildren(int profile, const BookmarkNode* parent) { - ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) - << "Node " << parent->GetTitle() << " does not belong to " - << "Profile " << profile; - verifier_helper_->SortChildren(GetBookmarkModel(profile), parent); - } + void SortChildren(int profile, const BookmarkNode* parent); // Reverses the order of the children of the node |parent| in the bookmark // model of profile |profile|. - void ReverseChildOrder(int profile, const BookmarkNode* parent) { - ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) - << "Node " << parent->GetTitle() << " does not belong to " - << "Profile " << profile; - verifier_helper_->ReverseChildOrder(GetBookmarkModel(profile), parent); - } + void ReverseChildOrder(int profile, const BookmarkNode* parent); // Checks if the bookmark model of profile |profile| matches the verifier // bookmark model. Returns true if they match. - bool ModelMatchesVerifier(int profile) WARN_UNUSED_RESULT { - if (verifier_helper_->use_verifier_model() == false) { - LOG(ERROR) << "Illegal to call ModelMatchesVerifier() after " - << "DisableVerifier(). Use ModelsMatch() instead."; - return false; - } - return BookmarkModelVerifier::ModelsMatch( - GetVerifierBookmarkModel(), GetBookmarkModel(profile)); - } + bool ModelMatchesVerifier(int profile) WARN_UNUSED_RESULT; // Checks if the bookmark models of all sync profiles match the verifier // bookmark model. Returns true if they match. - bool AllModelsMatchVerifier() WARN_UNUSED_RESULT { - if (verifier_helper_->use_verifier_model() == false) { - LOG(ERROR) << "Illegal to call AllModelsMatchVerifier() after " - << "DisableVerifier(). Use AllModelsMatch() instead."; - return false; - } - for (int i = 0; i < num_clients(); ++i) { - if (!ModelMatchesVerifier(i)) { - LOG(ERROR) << "Model " << i << " does not match the verifier."; - return false; - } - } - return true; - } + bool AllModelsMatchVerifier() WARN_UNUSED_RESULT; // Checks if the bookmark models of |profile_a| and |profile_b| match each // other. Returns true if they match. - bool ModelsMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT { - return BookmarkModelVerifier::ModelsMatch( - GetBookmarkModel(profile_a), GetBookmarkModel(profile_b)); - } + bool ModelsMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; // Checks if the bookmark models of all sync profiles match each other. Does // not compare them with the verifier bookmark model. Returns true if they // match. - bool AllModelsMatch() WARN_UNUSED_RESULT { - for (int i = 1; i < num_clients(); ++i) { - if (!ModelsMatch(0, i)) { - LOG(ERROR) << "Model " << i << " does not match Model 0."; - return false; - } - } - return true; - } + bool AllModelsMatch() WARN_UNUSED_RESULT; // Checks if the bookmark model of profile |profile| contains any instances of // two bookmarks with the same URL under the same parent folder. Returns true // if even one instance is found. - bool ContainsDuplicateBookmarks(int profile) { - return BookmarkModelVerifier::ContainsDuplicateBookmarks( - GetBookmarkModel(profile)); - } + bool ContainsDuplicateBookmarks(int profile); // Gets the node in the bookmark model of profile |profile| that has the url // |url|. Note: Only one instance of |url| is assumed to be present. const BookmarkNode* GetUniqueNodeByURL(int profile, - const GURL& url) WARN_UNUSED_RESULT { - std::vector<const BookmarkNode*> nodes; - GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); - EXPECT_EQ(1U, nodes.size()); - if (nodes.empty()) - return NULL; - return nodes[0]; - } + const GURL& url) WARN_UNUSED_RESULT; // Returns the number of bookmarks in bookmark model of profile |profile| // whose titles match the string |title|. int CountBookmarksWithTitlesMatching(int profile, const std::wstring& title) - WARN_UNUSED_RESULT { - return verifier_helper_->CountNodesWithTitlesMatching( - GetBookmarkModel(profile), BookmarkNode::URL, WideToUTF16(title)); - } + WARN_UNUSED_RESULT; // Returns the number of bookmark folders in the bookmark model of profile // |profile| whose titles contain the query string |title|. - int CountFoldersWithTitlesMatching(int profile, - const std::wstring& title) WARN_UNUSED_RESULT { - return verifier_helper_->CountNodesWithTitlesMatching( - GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title)); - } + int CountFoldersWithTitlesMatching( + int profile, + const std::wstring& title) WARN_UNUSED_RESULT; // Creates a unique favicon using |seed|. - static std::vector<unsigned char> CreateFavicon(int seed) { - const int w = 16; - const int h = 16; - SkBitmap bmp; - bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h); - bmp.allocPixels(); - uint32_t* src_data = bmp.getAddr32(0, 0); - for (int i = 0; i < w * h; ++i) { - src_data[i] = SkPreMultiplyARGB((seed + i) % 255, - (seed + i) % 250, - (seed + i) % 245, - (seed + i) % 240); - } - std::vector<unsigned char> favicon; - gfx::PNGCodec::EncodeBGRASkBitmap(bmp, false, &favicon); - return favicon; - } + static std::vector<unsigned char> CreateFavicon(int seed); private: // Helper object that has the functionality to verify changes made to the diff --git a/chrome/test/live_sync/live_sessions_sync_test.cc b/chrome/test/live_sync/live_sessions_sync_test.cc new file mode 100644 index 0000000..f6908f3 --- /dev/null +++ b/chrome/test/live_sync/live_sessions_sync_test.cc @@ -0,0 +1,312 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_sessions_sync_test.h" + +#include "chrome/browser/browser_thread.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sessions/session_service.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/test/ui_test_utils.h" +#include "googleurl/src/gurl.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" + +TestSessionService::TestSessionService() + : SessionServiceTestHelper(), + done_saving_(false, false), + got_windows_(false, false), + profile_(NULL), + window_bounds_(0, 1, 2, 3) {} + +TestSessionService::TestSessionService(SessionService* service, + Profile* profile) + : SessionServiceTestHelper(service), + done_saving_(false, false), + got_windows_(false, false), + profile_(profile), + window_bounds_(0, 1, 2, 3) {} + +void TestSessionService::SetUp() { + ASSERT_TRUE(service()) << "SetUp() called without setting SessionService"; + ASSERT_TRUE(profile_); + service()->SetWindowType(window_id_, Browser::TYPE_NORMAL); + service()->SetWindowBounds(window_id_, window_bounds_, false); +} + +void TestSessionService::Save() { + service()->Save(); +} + +std::vector<SessionWindow*>* TestSessionService::ReadWindows() { + // The session backend will post the callback as a task to whatever thread + // called it. In our case, we don't want the main test thread to have tasks + // posted to, so we perform the actual call to session service from the same + // thread the work will be done on (backend_thread aka file thread). As a + // result, it will directly call back, instead of posting a task, and we can + // block on that callback. + BrowserThread::PostTask( + BrowserThread::FILE, + FROM_HERE, + NewRunnableMethod(this, &TestSessionService::DoReadWindows)); + + // Wait for callback to happen. + got_windows_.Wait(); + + // By the time we reach here we've received the windows, so return them. + return windows_; +} + + +void TestSessionService::DoReadWindows() { + if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { + LOG(ERROR) << "DoReadWindows called from wrong thread!"; + windows_ = NULL; + got_windows_.Signal(); + return; + } + SessionService::SessionCallback* callback = + NewCallback(this, &TestSessionService::OnGotSession); + service()->GetCurrentSession(&consumer_, callback); +} + +void TestSessionService::OnGotSession(int handle, + std::vector<SessionWindow*>* windows) { + scoped_ptr<ForeignSession> foreign_session(new ForeignSession()); + for (size_t w = 0; w < windows->size(); ++w) { + const SessionWindow& window = *windows->at(w); + scoped_ptr<SessionWindow> new_window(new SessionWindow()); + for (size_t t = 0; t < window.tabs.size(); ++t) { + const SessionTab& tab = *window.tabs.at(t); + scoped_ptr<SessionTab> new_tab(new SessionTab()); + new_tab->navigations.resize(tab.navigations.size()); + std::copy(tab.navigations.begin(), tab.navigations.end(), + new_tab->navigations.begin()); + new_window->tabs.push_back(new_tab.release()); + } + foreign_session->windows.push_back(new_window.release()); + } + windows_ = &(foreign_session->windows); + foreign_sessions_.push_back(foreign_session.release()); + got_windows_.Signal(); +} + +TestSessionService::~TestSessionService() { + ReleaseService(); // We don't own this, so don't destroy it. +} + +LiveSessionsSyncTest::LiveSessionsSyncTest(TestType test_type) + : LiveSyncTest(test_type), + done_closing_(false, false) {} + +LiveSessionsSyncTest::~LiveSessionsSyncTest() {} + +SessionService* LiveSessionsSyncTest::GetSessionService(int index) { + return GetProfile(index)->GetSessionService(); +} + +TestSessionService* LiveSessionsSyncTest::GetHelper(int index) { + return test_session_services_[index]->get(); +} + +Browser* LiveSessionsSyncTest::GetBrowser(int index) { + return browsers_[index]; +} + +bool LiveSessionsSyncTest::SetupClients() { + if (!LiveSyncTest::SetupClients()) { + return false; + } + + // Go through and make the TestSessionServices and Browsers. + for (int i = 0; i < num_clients(); ++i) { + scoped_refptr<TestSessionService>* new_tester = + new scoped_refptr<TestSessionService>; + *new_tester = new TestSessionService( + GetSessionService(i), GetProfile(i)); + test_session_services_.push_back(new_tester); + GetHelper(i)->SetUp(); + + browsers_.push_back(Browser::Create(GetProfile(i))); + } + + return true; +} + +TabContents* LiveSessionsSyncTest::OpenTab(int index, GURL url) { + TabContents* tab = + GetBrowser(index)-> + AddSelectedTabWithURL(url, PageTransition::START_PAGE)->tab_contents(); + + // Wait for the page to finish loading. + ui_test_utils::WaitForNavigation( + &GetBrowser(index)->GetSelectedTabContents()->controller()); + + return tab; +} + +std::vector<SessionWindow*>* LiveSessionsSyncTest::InitializeNewWindowWithTab( + int index, GURL url) { + if (!OpenTab(index, url)) { + return NULL; + } + GetHelper(index)->Save(); + std::vector<SessionWindow*>* windows = GetHelper(index)->ReadWindows(); + if (windows->size() != 1) { + LOG(ERROR) << "InitializeNewWindowWithTab called with open windows!"; + return NULL; + } + if (1U != (*windows)[0]->tabs.size()) + return NULL; + SortSessionWindows(windows); + return windows; +} + +bool LiveSessionsSyncTest::CheckInitialState(int index) { + if (0 != GetNumWindows(index)) + return false; + if (0 != GetNumForeignSessions(index)) + return false; + return true; +} + +int LiveSessionsSyncTest::GetNumWindows(int index) { + // We don't own windows. + std::vector<SessionWindow*>* windows = GetHelper(index)->ReadWindows(); + return windows->size(); +} + +int LiveSessionsSyncTest::GetNumForeignSessions(int index) { + std::vector<const ForeignSession*> sessions; + if (!GetProfile(index)->GetProfileSyncService()-> + GetSessionModelAssociator()->GetAllForeignSessions(&sessions)) + return 0; + return sessions.size(); +} + +bool LiveSessionsSyncTest::GetSessionData( + int index, + std::vector<const ForeignSession*>* sessions) { + if (!GetProfile(index)->GetProfileSyncService()-> + GetSessionModelAssociator()->GetAllForeignSessions(sessions)) + return false; + SortForeignSessions(sessions); + return true; +} + +// static +bool LiveSessionsSyncTest::CompareSessionWindows(SessionWindow* lhs, + SessionWindow* rhs) { + if (!lhs || + !rhs || + lhs->tabs.size() < 1 || + rhs->tabs.size() < 1 || + lhs->tabs[0]->navigations.size() < 1 || + rhs->tabs[0]->navigations.size() < 1) { + // Catchall for uncomparable data. + return false; + } + + return lhs->tabs[0]->navigations[0].virtual_url() < + rhs->tabs[0]->navigations[0].virtual_url(); +} + +void LiveSessionsSyncTest::SortSessionWindows( + std::vector<SessionWindow*>* windows) { + std::sort(windows->begin(), windows->end(), + LiveSessionsSyncTest::CompareSessionWindows); +} + +//static +bool LiveSessionsSyncTest::CompareForeignSessions( + const ForeignSession* lhs, + const ForeignSession* rhs) { + if (!lhs || + !rhs || + lhs->windows.size() < 1 || + rhs->windows.size() < 1) { + // Catchall for uncomparable data. + return false; + } + + return CompareSessionWindows(lhs->windows[0], rhs->windows[0]); +} + +void LiveSessionsSyncTest::SortForeignSessions( + std::vector<const ForeignSession*>* sessions) { + std::sort(sessions->begin(), sessions->end(), + LiveSessionsSyncTest::CompareForeignSessions); +} + +bool LiveSessionsSyncTest::NavigationEquals(const TabNavigation& expected, + const TabNavigation& actual) { + if (expected.virtual_url() != actual.virtual_url()) + return false; + if (expected.referrer() != actual.referrer()) + return false; + if (expected.title() != actual.title()) + return false; + if (expected.transition() != actual.transition()) + return false; + return true; +} + +bool LiveSessionsSyncTest::WindowsMatch( + const std::vector<SessionWindow*> &win1, + const std::vector<SessionWindow*> &win2) { + SessionTab* client0_tab; + SessionTab* client1_tab; + if (win1.size() != win2.size()) + return false; + for (size_t i = 0; i < win1.size(); ++i) { + if (win1[i]->tabs.size() != win2[i]->tabs.size()) + return false; + for (size_t j = 0; j < win1[i]->tabs.size(); ++j) { + client0_tab = win1[i]->tabs[j]; + client1_tab = win2[i]->tabs[j]; + for (size_t k = 0; k < client0_tab->navigations.size(); ++k) { + if (!NavigationEquals(client0_tab->navigations[k], + client1_tab->navigations[k])) { + return false; + } + } + } + } + + return true; +} + +bool LiveSessionsSyncTest::CheckForeignSessionsAgainst( + int index, + const std::vector<std::vector<SessionWindow*>* >& windows) { + std::vector<const ForeignSession*> sessions; + if (!GetSessionData(index, &sessions)) + return false; + if ((size_t)(num_clients()-1) != sessions.size()) + return false; + + int window_index = 0; + for (size_t j = 0; j < sessions.size(); ++j, ++window_index) { + if (window_index == index) + window_index++; // Skip self. + if (!WindowsMatch(sessions[j]->windows, *windows[window_index])) + return false; + } + + return true; +} + +void LiveSessionsSyncTest::CleanUpOnMainThread() { + // Close all browsers. We need to do this now, as opposed to letting the + // test framework handle it, because we created our own browser for each + // sync profile. + BrowserList::CloseAllBrowsers(); + ui_test_utils::RunAllPendingInMessageLoop(); + + // All browsers should be closed at this point, else when the framework + // calls QuitBrowsers() we could see memory corruption. + ASSERT_EQ(0U, BrowserList::size()); + + LiveSyncTest::CleanUpOnMainThread(); +} diff --git a/chrome/test/live_sync/live_sessions_sync_test.h b/chrome/test/live_sync/live_sessions_sync_test.h index 09939bf..e081ad7 100644 --- a/chrome/test/live_sync/live_sessions_sync_test.h +++ b/chrome/test/live_sync/live_sessions_sync_test.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,111 +13,44 @@ #include "base/scoped_vector.h" #include "base/ref_counted.h" #include "base/synchronization/waitable_event.h" -#include "chrome/browser/browser_window.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/sessions/base_session_service.h" #include "chrome/browser/sessions/session_service_test_helper.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/browser/sessions/session_types.h" #include "chrome/test/live_sync/live_sync_test.h" -#include "chrome/test/ui_test_utils.h" -#include "googleurl/src/gurl.h" -#include "webkit/glue/window_open_disposition.h" + +class GURL; +class Profile; +class TabContents; // Helper for accessing session service internals. class TestSessionService : public SessionServiceTestHelper, public base::RefCountedThreadSafe<TestSessionService> { public: - TestSessionService() - : SessionServiceTestHelper(), - done_saving_(false, false), - got_windows_(false, false), - profile_(NULL), - window_bounds_(0, 1, 2, 3) {} - TestSessionService(SessionService* service, Profile* profile) - : SessionServiceTestHelper(service), - done_saving_(false, false), - got_windows_(false, false), - profile_(profile), - window_bounds_(0, 1, 2, 3) {} - - void SetUp() { - ASSERT_TRUE(service()) << "SetUp() called without setting SessionService"; - ASSERT_TRUE(profile_); - service()->SetWindowType(window_id_, Browser::TYPE_NORMAL); - service()->SetWindowBounds(window_id_, window_bounds_, false); - } + TestSessionService(); + TestSessionService(SessionService* service, Profile* profile); + + void SetUp(); // Trigger saving the current session commands to file. - void Save() { - service()->Save(); - } + void Save(); // Synchronously reads the contents of the current session. - std::vector<SessionWindow*>* ReadWindows() { - // The session backend will post the callback as a task to whatever thread - // called it. In our case, we don't want the main test thread to have tasks - // posted to, so we perform the actual call to session service from the same - // thread the work will be done on (backend_thread aka file thread). As a - // result, it will directly call back, instead of posting a task, and we can - // block on that callback. - BrowserThread::PostTask( - BrowserThread::FILE, - FROM_HERE, - NewRunnableMethod(this, &TestSessionService::DoReadWindows)); - - // Wait for callback to happen. - got_windows_.Wait(); - - // By the time we reach here we've received the windows, so return them. - return windows_; - } + std::vector<SessionWindow*>* ReadWindows(); // Makes the actual call to session service. // Lives on the file thread. - void DoReadWindows() { - if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { - LOG(ERROR) << "DoReadWindows called from wrong thread!"; - windows_ = NULL; - got_windows_.Signal(); - return; - } - SessionService::SessionCallback* callback = - NewCallback(this, &TestSessionService::OnGotSession); - service()->GetCurrentSession(&consumer_, callback); - } + void DoReadWindows(); // Internal method used in the callback to obtain the current session. // Lives on and called from backend thread (file_thread). // We don't own windows so need to make a deep copy. // In this case, we only copy those values compared against in WindowsMatch // (number of windows, number of tabs, and navigations within tabs). - void OnGotSession(int handle, std::vector<SessionWindow*>* windows) { - scoped_ptr<ForeignSession> foreign_session(new ForeignSession()); - for (size_t w = 0; w < windows->size(); ++w) { - const SessionWindow& window = *windows->at(w); - scoped_ptr<SessionWindow> new_window(new SessionWindow()); - for (size_t t = 0; t < window.tabs.size(); ++t) { - const SessionTab& tab = *window.tabs.at(t); - scoped_ptr<SessionTab> new_tab(new SessionTab()); - new_tab->navigations.resize(tab.navigations.size()); - std::copy(tab.navigations.begin(), tab.navigations.end(), - new_tab->navigations.begin()); - new_window->tabs.push_back(new_tab.release()); - } - foreign_session->windows.push_back(new_window.release()); - } - windows_ = &(foreign_session->windows); - foreign_sessions_.push_back(foreign_session.release()); - got_windows_.Signal(); - } + void OnGotSession(int handle, std::vector<SessionWindow*>* windows); private: - ~TestSessionService() { - ReleaseService(); // We don't own this, so don't destroy it. - } + virtual ~TestSessionService(); friend class base::RefCountedThreadSafe<TestSessionService>; @@ -148,177 +81,67 @@ class TestSessionService class LiveSessionsSyncTest : public LiveSyncTest { public: - explicit LiveSessionsSyncTest(TestType test_type) - : LiveSyncTest(test_type), - done_closing_(false, false) {} - virtual ~LiveSessionsSyncTest() {} + explicit LiveSessionsSyncTest(TestType test_type); + virtual ~LiveSessionsSyncTest(); // Used to access the session service associated with a specific sync profile. - SessionService* GetSessionService(int index) { - return GetProfile(index)->GetSessionService(); - } + SessionService* GetSessionService(int index); // Used to access the session service test helper associated with a specific // sync profile. - TestSessionService* GetHelper(int index) { - return test_session_services_[index]->get(); - } + TestSessionService* GetHelper(int index); // Used to access the browser associated with a specific sync profile. - Browser* GetBrowser(int index) { - return browsers_[index]; - } + Browser* GetBrowser(int index); // Sets up the TestSessionService helper and the new browser windows. - bool SetupClients() { - if (!LiveSyncTest::SetupClients()) { - return false; - } - - // Go through and make the TestSessionServices and Browsers. - for (int i = 0; i < num_clients(); ++i) { - scoped_refptr<TestSessionService>* new_tester = - new scoped_refptr<TestSessionService>; - *new_tester = new TestSessionService( - GetSessionService(i), GetProfile(i)); - test_session_services_.push_back(new_tester); - GetHelper(i)->SetUp(); - - browsers_.push_back(Browser::Create(GetProfile(i))); - } - - return true; - } + bool SetupClients(); // Open a single tab and return the TabContents. TabContents must be checked // to ensure the tab opened successsfully. - TabContents* OpenTab(int index, GURL url) WARN_UNUSED_RESULT { - TabContents* tab = GetBrowser(index)-> - AddSelectedTabWithURL(url, PageTransition::START_PAGE)->tab_contents(); - - // Wait for the page to finish loading. - ui_test_utils::WaitForNavigation( - &GetBrowser(index)->GetSelectedTabContents()->controller()); - - return tab; - } + TabContents* OpenTab(int index, GURL url) WARN_UNUSED_RESULT; // Creates and verifies the creation of a new window with one tab displaying // the specified GURL. // Returns: the SessionWindow associated with the new window. std::vector<SessionWindow*>* InitializeNewWindowWithTab(int index, GURL url) - WARN_UNUSED_RESULT { - if (!OpenTab(index, url)) { - return NULL; - } - GetHelper(index)->Save(); - std::vector<SessionWindow*>* windows = GetHelper(index)->ReadWindows(); - if (windows->size() != 1) { - LOG(ERROR) << "InitializeNewWindowWithTab called with open windows!"; - return NULL; - } - if (1U != (*windows)[0]->tabs.size()) - return NULL; - SortSessionWindows(windows); - return windows; - } + WARN_UNUSED_RESULT; // Checks that window count and foreign session count are 0. - bool CheckInitialState(int index) WARN_UNUSED_RESULT { - if (0 != GetNumWindows(index)) - return false; - if (0 != GetNumForeignSessions(index)) - return false; - return true; - } + bool CheckInitialState(int index) WARN_UNUSED_RESULT; // Returns number of open windows for a profile. - int GetNumWindows(int index) { - // We don't own windows. - std::vector<SessionWindow*>* windows = GetHelper(index)->ReadWindows(); - return windows->size(); - } + int GetNumWindows(int index); // Returns number of foreign sessions for a profile. - int GetNumForeignSessions(int index) { - std::vector<const ForeignSession*> sessions; - if (!GetProfile(index)->GetProfileSyncService()-> - GetSessionModelAssociator()->GetAllForeignSessions(&sessions)) - return 0; - return sessions.size(); - } + int GetNumForeignSessions(int index); // Fills the sessions vector with the model associator's foreign session data. // Caller owns |sessions|, but not ForeignSession objects within. bool GetSessionData(int index, std::vector<const ForeignSession*>* sessions) - WARN_UNUSED_RESULT { - if (!GetProfile(index)->GetProfileSyncService()-> - GetSessionModelAssociator()->GetAllForeignSessions(sessions)) - return false; - SortForeignSessions(sessions); - return true; - } + WARN_UNUSED_RESULT; // Compare session windows based on their first tab's url. // Returns true if the virtual url of the lhs is < the rhs. - static bool CompareSessionWindows(SessionWindow* lhs, SessionWindow* rhs) { - if (!lhs || - !rhs || - lhs->tabs.size() < 1 || - rhs->tabs.size() < 1 || - lhs->tabs[0]->navigations.size() < 1 || - rhs->tabs[0]->navigations.size() < 1) { - // Catchall for uncomparable data. - return false; - } - - return lhs->tabs[0]->navigations[0].virtual_url() < - rhs->tabs[0]->navigations[0].virtual_url(); - } + static bool CompareSessionWindows(SessionWindow* lhs, SessionWindow* rhs); // Sort session windows using our custom comparator (first tab url // comparison). - void SortSessionWindows(std::vector<SessionWindow*>* windows) { - std::sort(windows->begin(), windows->end(), - LiveSessionsSyncTest::CompareSessionWindows); - } + void SortSessionWindows(std::vector<SessionWindow*>* windows); // Compares a foreign session based on the first session window. // Returns true based on the comparison of the session windows. static bool CompareForeignSessions( const ForeignSession* lhs, - const ForeignSession* rhs) { - if (!lhs || - !rhs || - lhs->windows.size() < 1 || - rhs->windows.size() < 1) { - // Catchall for uncomparable data. - return false; - } - - return CompareSessionWindows(lhs->windows[0], rhs->windows[0]); - } + const ForeignSession* rhs); // Sort a foreign session vector using our custom foreign session comparator. - void SortForeignSessions(std::vector<const ForeignSession*>* sessions) { - std::sort(sessions->begin(), sessions->end(), - LiveSessionsSyncTest::CompareForeignSessions); - } + void SortForeignSessions(std::vector<const ForeignSession*>* sessions); // Compares two tab navigations base on the parameters we sync. // (Namely, we don't sync state or type mask) bool NavigationEquals(const TabNavigation& expected, - const TabNavigation& actual) { - if (expected.virtual_url() != actual.virtual_url()) - return false; - if (expected.referrer() != actual.referrer()) - return false; - if (expected.title() != actual.title()) - return false; - if (expected.transition() != actual.transition()) - return false; - return true; - } + const TabNavigation& actual); // Verifies that two SessionWindows match. // Returns: @@ -329,28 +152,7 @@ class LiveSessionsSyncTest : public LiveSyncTest { // 4. actual tab navigations contents // - false otherwise. bool WindowsMatch(const std::vector<SessionWindow*> &win1, - const std::vector<SessionWindow*> &win2) WARN_UNUSED_RESULT { - SessionTab* client0_tab; - SessionTab* client1_tab; - if (win1.size() != win2.size()) - return false; - for (size_t i = 0; i < win1.size(); ++i) { - if (win1[i]->tabs.size() != win2[i]->tabs.size()) - return false; - for (size_t j = 0; j < win1[i]->tabs.size(); ++j) { - client0_tab = win1[i]->tabs[j]; - client1_tab = win2[i]->tabs[j]; - for (size_t k = 0; k < client0_tab->navigations.size(); ++k) { - if (!NavigationEquals(client0_tab->navigations[k], - client1_tab->navigations[k])) { - return false; - } - } - } - } - - return true; - } + const std::vector<SessionWindow*> &win2) WARN_UNUSED_RESULT; // Retrieves the foreign sessions for a particular profile and compares them // with a reference SessionWindow list. @@ -358,39 +160,11 @@ class LiveSessionsSyncTest : public LiveSyncTest { // reference. bool CheckForeignSessionsAgainst(int index, const std::vector<std::vector<SessionWindow*>* >& windows) - WARN_UNUSED_RESULT { - std::vector<const ForeignSession*> sessions; - if (!GetSessionData(index, &sessions)) - return false; - if ((size_t)(num_clients()-1) != sessions.size()) - return false; - - int window_index = 0; - for (size_t j = 0; j < sessions.size(); ++j, ++window_index) { - if (window_index == index) - window_index++; // Skip self. - if (!WindowsMatch(sessions[j]->windows, *windows[window_index])) - return false; - } - - return true; - } + WARN_UNUSED_RESULT; protected: // Clean up our mess. - virtual void CleanUpOnMainThread() { - // Close all browsers. We need to do this now, as opposed to letting the - // test framework handle it, because we created our own browser for each - // sync profile. - BrowserList::CloseAllBrowsers(); - ui_test_utils::RunAllPendingInMessageLoop(); - - // All browsers should be closed at this point, else when the framework - // calls QuitBrowsers() we could see memory corruption. - ASSERT_EQ(0U, BrowserList::size()); - - LiveSyncTest::CleanUpOnMainThread(); - } + virtual void CleanUpOnMainThread(); // Vector of our TestSessionService helpers. ScopedVector<scoped_refptr<TestSessionService> > test_session_services_; diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc index 21146e9..e9ac0f3 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -20,10 +20,12 @@ #include "chrome/browser/password_manager/encryptor.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/url_fetcher.h" #include "chrome/common/net/url_request_context_getter.h" +#include "chrome/common/net/test_url_fetcher_factory.h" #include "chrome/test/testing_browser_process.h" #include "chrome/test/ui_test_utils.h" #include "googleurl/src/gurl.h" @@ -126,6 +128,8 @@ LiveSyncTest::LiveSyncTest(TestType test_type) } } +LiveSyncTest::~LiveSyncTest() {} + void LiveSyncTest::SetUp() { CommandLine* cl = CommandLine::ForCurrentProcess(); if (cl->HasSwitch(switches::kPasswordFileForTest)) { diff --git a/chrome/test/live_sync/live_sync_test.h b/chrome/test/live_sync/live_sync_test.h index 21c3cf8..2c6bb5b 100644 --- a/chrome/test/live_sync/live_sync_test.h +++ b/chrome/test/live_sync/live_sync_test.h @@ -13,8 +13,6 @@ #include "base/process_util.h" #include "base/scoped_ptr.h" #include "base/scoped_vector.h" -#include "chrome/browser/sync/profile_sync_service_harness.h" -#include "chrome/common/net/test_url_fetcher_factory.h" #include "net/base/mock_host_resolver.h" #include "net/test/test_server.h" @@ -23,7 +21,9 @@ class CommandLine; class Profile; +class ProfileSyncServiceHarness; class URLRequestContextGetter; +class FakeURLFetcherFactory; namespace net { class ProxyConfig; @@ -58,7 +58,7 @@ class LiveSyncTest : public InProcessBrowserTest { // A LiveSyncTest must be associated with a particular test type. explicit LiveSyncTest(TestType test_type); - virtual ~LiveSyncTest() {} + virtual ~LiveSyncTest(); // Validates command line parameters and creates a local python test server if // specified. diff --git a/chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc index eae27fd..4ea96b0 100644 --- a/chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc +++ b/chrome/test/live_sync/many_client_live_bookmarks_sync_test.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/live_sync/live_bookmarks_sync_test.h" - #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" +#include "chrome/test/live_sync/live_bookmarks_sync_test.h" // TODO(rsimha): Enable once http://crbug.com/69604 is fixed. IN_PROC_BROWSER_TEST_F(ManyClientLiveBookmarksSyncTest, DISABLED_Sanity) { diff --git a/chrome/test/live_sync/many_client_live_passwords_sync_test.cc b/chrome/test/live_sync/many_client_live_passwords_sync_test.cc index 7f7b0a6..e4e54bd 100644 --- a/chrome/test/live_sync/many_client_live_passwords_sync_test.cc +++ b/chrome/test/live_sync/many_client_live_passwords_sync_test.cc @@ -1,8 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/utf_string_conversions.h" #include "chrome/browser/password_manager/password_form_data.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/test/live_sync/live_passwords_sync_test.h" using webkit_glue::PasswordForm; diff --git a/chrome/test/live_sync/many_client_live_preferences_sync_test.cc b/chrome/test/live_sync/many_client_live_preferences_sync_test.cc index dd3daad..db132f4 100644 --- a/chrome/test/live_sync/many_client_live_preferences_sync_test.cc +++ b/chrome/test/live_sync/many_client_live_preferences_sync_test.cc @@ -1,7 +1,8 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/common/pref_names.h" #include "chrome/test/live_sync/live_preferences_sync_test.h" diff --git a/chrome/test/live_sync/multiple_client_live_passwords_sync_test.cc b/chrome/test/live_sync/multiple_client_live_passwords_sync_test.cc index 0b23e35..bc50048 100644 --- a/chrome/test/live_sync/multiple_client_live_passwords_sync_test.cc +++ b/chrome/test/live_sync/multiple_client_live_passwords_sync_test.cc @@ -1,8 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/stringprintf.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/password_manager/password_form_data.h" #include "chrome/test/live_sync/live_passwords_sync_test.h" diff --git a/chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc b/chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc index 45adf2c..d14c36a 100644 --- a/chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc +++ b/chrome/test/live_sync/multiple_client_live_preferences_sync_test.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/scoped_ptr.h" #include "base/string_util.h" #include "chrome/browser/prefs/scoped_pref_update.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/common/pref_names.h" #include "chrome/test/live_sync/live_preferences_sync_test.h" diff --git a/chrome/test/live_sync/multiple_client_live_sessions_sync_test.cc b/chrome/test/live_sync/multiple_client_live_sessions_sync_test.cc index f5e8e1e..5183b0b 100644 --- a/chrome/test/live_sync/multiple_client_live_sessions_sync_test.cc +++ b/chrome/test/live_sync/multiple_client_live_sessions_sync_test.cc @@ -1,8 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/stringprintf.h" +#include "chrome/browser/sessions/session_service.h" +#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/test/live_sync/live_sessions_sync_test.h" IN_PROC_BROWSER_TEST_F(MultipleClientLiveSessionsSyncTest, AllChanged) { diff --git a/chrome/test/live_sync/single_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/single_client_live_bookmarks_sync_test.cc index 33c0b50..75cb8e4 100644 --- a/chrome/test/live_sync/single_client_live_bookmarks_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_bookmarks_sync_test.cc @@ -1,10 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/live_sync/live_bookmarks_sync_test.h" - #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" +#include "chrome/test/live_sync/live_bookmarks_sync_test.h" IN_PROC_BROWSER_TEST_F(SingleClientLiveBookmarksSyncTest, OfflineToOnline) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; diff --git a/chrome/test/live_sync/single_client_live_extensions_sync_test.cc b/chrome/test/live_sync/single_client_live_extensions_sync_test.cc index 512337f..801ea6a 100644 --- a/chrome/test/live_sync/single_client_live_extensions_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_extensions_sync_test.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/live_sync/live_extensions_sync_test.h" - #include "base/basictypes.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/common/extensions/extension.h" +#include "chrome/test/live_sync/live_extensions_sync_test.h" class SingleClientLiveExtensionsSyncTest : public LiveExtensionsSyncTest { public: diff --git a/chrome/test/live_sync/single_client_live_passwords_sync_test.cc b/chrome/test/live_sync/single_client_live_passwords_sync_test.cc index ffeacd8..400eb1b6 100644 --- a/chrome/test/live_sync/single_client_live_passwords_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_passwords_sync_test.cc @@ -1,8 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/password_manager/password_form_data.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/test/live_sync/live_passwords_sync_test.h" using webkit_glue::PasswordForm; diff --git a/chrome/test/live_sync/single_client_live_preferences_sync_test.cc b/chrome/test/live_sync/single_client_live_preferences_sync_test.cc index 6782f04..6333ac9 100644 --- a/chrome/test/live_sync/single_client_live_preferences_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_preferences_sync_test.cc @@ -1,8 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/common/pref_names.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/test/live_sync/live_preferences_sync_test.h" IN_PROC_BROWSER_TEST_F(SingleClientLivePreferencesSyncTest, Sanity) { diff --git a/chrome/test/live_sync/single_client_live_sessions_sync_test.cc b/chrome/test/live_sync/single_client_live_sessions_sync_test.cc index 446dbd7..02de47d 100644 --- a/chrome/test/live_sync/single_client_live_sessions_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_sessions_sync_test.cc @@ -1,8 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/scoped_vector.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/test/live_sync/live_sessions_sync_test.h" IN_PROC_BROWSER_TEST_F(SingleClientLiveSessionsSyncTest, Sanity) { diff --git a/chrome/test/live_sync/single_client_live_themes_sync_test.cc b/chrome/test/live_sync/single_client_live_themes_sync_test.cc index ea45c60..c901947 100644 --- a/chrome/test/live_sync/single_client_live_themes_sync_test.cc +++ b/chrome/test/live_sync/single_client_live_themes_sync_test.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/live_sync/live_themes_sync_test.h" - #include "base/basictypes.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/common/extensions/extension.h" +#include "chrome/test/live_sync/live_themes_sync_test.h" class SingleClientLiveThemesSyncTest : public LiveThemesSyncTest { public: diff --git a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc index 6a9a55e..263eaef 100644 --- a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc @@ -1,8 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/utf_string_conversions.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/test/live_sync/live_autofill_sync_test.h" IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, WebDataServiceSanity) { diff --git a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc index 7255c9f..4af52a1 100644 --- a/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_bookmarks_sync_test.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/live_sync/live_bookmarks_sync_test.h" - #include "base/rand_util.h" #include "base/stringprintf.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" +#include "chrome/test/live_sync/live_bookmarks_sync_test.h" const std::string kGenericURL = "http://www.host.ext:1234/path/filename"; const std::wstring kGenericURLTitle = L"URL Title"; diff --git a/chrome/test/live_sync/two_client_live_passwords_sync_test.cc b/chrome/test/live_sync/two_client_live_passwords_sync_test.cc index 6e77859..e308104 100644 --- a/chrome/test/live_sync/two_client_live_passwords_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_passwords_sync_test.cc @@ -1,8 +1,10 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/utf_string_conversions.h" #include "chrome/browser/password_manager/password_form_data.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/sessions/session_state.h" #include "chrome/test/live_sync/live_passwords_sync_test.h" diff --git a/chrome/test/live_sync/two_client_live_preferences_sync_test.cc b/chrome/test/live_sync/two_client_live_preferences_sync_test.cc index d0f65a1..aa1e319 100644 --- a/chrome/test/live_sync/two_client_live_preferences_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_preferences_sync_test.cc @@ -1,8 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/prefs/scoped_pref_update.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/translate/translate_prefs.h" #include "chrome/common/pref_names.h" #include "chrome/test/live_sync/live_preferences_sync_test.h" diff --git a/chrome/test/live_sync/two_client_live_sessions_sync_test.cc b/chrome/test/live_sync/two_client_live_sessions_sync_test.cc index e493e8e..7294c07 100644 --- a/chrome/test/live_sync/two_client_live_sessions_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_sessions_sync_test.cc @@ -1,7 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/sessions/session_service.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/test/live_sync/live_sessions_sync_test.h" // @TODO(zea): Test each individual session command we care about separately. diff --git a/chrome/test/live_sync/two_client_live_themes_sync_test.cc b/chrome/test/live_sync/two_client_live_themes_sync_test.cc index 18c5d19..29ba596 100644 --- a/chrome/test/live_sync/two_client_live_themes_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_themes_sync_test.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/test/live_sync/live_themes_sync_test.h" - #include "base/basictypes.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/common/extensions/extension.h" +#include "chrome/test/live_sync/live_themes_sync_test.h" class TwoClientLiveThemesSyncTest : public LiveThemesSyncTest { public: diff --git a/chrome/test/sync/engine/test_directory_setter_upper.cc b/chrome/test/sync/engine/test_directory_setter_upper.cc index 9777b32..a0e4431 100644 --- a/chrome/test/sync/engine/test_directory_setter_upper.cc +++ b/chrome/test/sync/engine/test_directory_setter_upper.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -125,6 +125,8 @@ MockDirectorySetterUpper::MockDirectorySetterUpper() : directory_(new MockDirectory(name())) { } +MockDirectorySetterUpper::~MockDirectorySetterUpper() {} + void MockDirectorySetterUpper::SetUp() { reset_directory_manager(new Manager(FilePath(), directory_.get())); } diff --git a/chrome/test/sync/engine/test_directory_setter_upper.h b/chrome/test/sync/engine/test_directory_setter_upper.h index fc5eb6f..00847ee 100644 --- a/chrome/test/sync/engine/test_directory_setter_upper.h +++ b/chrome/test/sync/engine/test_directory_setter_upper.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // @@ -121,6 +121,7 @@ class MockDirectorySetterUpper : public TestDirectorySetterUpper { }; MockDirectorySetterUpper(); + virtual ~MockDirectorySetterUpper(); virtual void SetUp(); virtual void TearDown(); diff --git a/chrome/test/webdriver/automation.cc b/chrome/test/webdriver/automation.cc index e0cd968..e0afa4d 100644 --- a/chrome/test/webdriver/automation.cc +++ b/chrome/test/webdriver/automation.cc @@ -8,11 +8,17 @@ #include "base/logging.h" #include "base/utf_string_conversions.h" #include "chrome/common/chrome_switches.h" +#include "chrome/test/automation/browser_proxy.h" +#include "chrome/test/automation/tab_proxy.h" #include "chrome/test/test_launcher_utils.h" #include "googleurl/src/gurl.h" namespace webdriver { +Automation::Automation() {} + +Automation::~Automation() {} + void Automation::Init(bool* success) { *success = false; diff --git a/chrome/test/webdriver/automation.h b/chrome/test/webdriver/automation.h index 4bf8758..10ab4a1 100644 --- a/chrome/test/webdriver/automation.h +++ b/chrome/test/webdriver/automation.h @@ -10,8 +10,6 @@ #include "base/task.h" #include "base/ref_counted.h" #include "base/scoped_temp_dir.h" -#include "chrome/test/automation/browser_proxy.h" -#include "chrome/test/automation/tab_proxy.h" #include "chrome/test/ui/ui_test.h" namespace webdriver { @@ -22,7 +20,8 @@ namespace webdriver { // http://code.google.com/p/chromium/issues/detail?id=56865 class Automation : private UITestBase { public: - Automation() {} + Automation(); + virtual ~Automation(); // Creates a browser. void Init(bool* success); diff --git a/chrome/test/webdriver/commands/command.cc b/chrome/test/webdriver/commands/command.cc index 3cf81bd..142c947 100644 --- a/chrome/test/webdriver/commands/command.cc +++ b/chrome/test/webdriver/commands/command.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,6 +17,29 @@ const char* const Response::kStackTrace = "stackTrace"; const char* const Response::kFileName = "fileName"; const char* const Response::kLineNumber = "lineNumber"; +Command::Command(const std::vector<std::string>& path_segments, + const DictionaryValue* const parameters) + : path_segments_(path_segments), + parameters_(parameters) {} + +Command::~Command() {} + +bool Command::DoesDelete() { + return false; +} + +bool Command::DoesGet() { + return false; +} + +bool Command::DoesPost() { + return false; +} + +bool Command::Init(Response* const response) { + return true; +} + bool Command::GetStringParameter(const std::string& key, string16* out) const { return parameters_.get() != NULL && parameters_->GetString(key, out); diff --git a/chrome/test/webdriver/commands/command.h b/chrome/test/webdriver/commands/command.h index 6d06033..ccb95b8 100644 --- a/chrome/test/webdriver/commands/command.h +++ b/chrome/test/webdriver/commands/command.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -24,21 +24,19 @@ namespace webdriver { // http://code.google.com/p/selenium/wiki/JsonWireProtocol class Command { public: - inline Command(const std::vector<std::string>& path_segments, - const DictionaryValue* const parameters) - : path_segments_(path_segments), - parameters_(parameters) {} - virtual ~Command() {} + Command(const std::vector<std::string>& path_segments, + const DictionaryValue* const parameters); + virtual ~Command(); // Indicates which HTTP methods this command URL responds to. - virtual bool DoesDelete() { return false; } - virtual bool DoesGet() { return false; } - virtual bool DoesPost() { return false; } + virtual bool DoesDelete(); + virtual bool DoesGet(); + virtual bool DoesPost(); // Initializes this command for execution. If initialization fails, will // return |false| and populate the |response| with the necessary information // to return to the client. - virtual bool Init(Response* const response) { return true; } + virtual bool Init(Response* const response); // Executes the corresponding variant of this command URL. // Always called after |Init()| and called from the Execute function. diff --git a/chrome/test/webdriver/commands/find_element_commands.cc b/chrome/test/webdriver/commands/find_element_commands.cc index 94d82c8..16f2454 100644 --- a/chrome/test/webdriver/commands/find_element_commands.cc +++ b/chrome/test/webdriver/commands/find_element_commands.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,6 +17,15 @@ namespace webdriver { +FindElementCommand::FindElementCommand( + const std::vector<std::string>& path_segments, + const DictionaryValue* const parameters, + const bool find_one_element) + : WebDriverCommand(path_segments, parameters), + find_one_element_(find_one_element) {} + +FindElementCommand::~FindElementCommand() {} + bool FindElementCommand::Init(Response* const response) { if (!WebDriverCommand::Init(response)) { SET_WEBDRIVER_ERROR(response, "Failure on Init for find element", @@ -49,6 +58,10 @@ bool FindElementCommand::Init(Response* const response) { return true; } +bool FindElementCommand::DoesPost() { + return true; +} + void FindElementCommand::ExecutePost(Response* const response) { scoped_ptr<ListValue> args(new ListValue()); DictionaryValue* locator = new DictionaryValue(); @@ -108,5 +121,9 @@ void FindElementCommand::ExecutePost(Response* const response) { response->set_status(error); } +bool FindElementCommand::RequiresValidTab() { + return false; +} + } // namespace webdriver diff --git a/chrome/test/webdriver/commands/find_element_commands.h b/chrome/test/webdriver/commands/find_element_commands.h index cc45d10..b9a6250 100644 --- a/chrome/test/webdriver/commands/find_element_commands.h +++ b/chrome/test/webdriver/commands/find_element_commands.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,18 +19,16 @@ class FindElementCommand : public WebDriverCommand { public: FindElementCommand(const std::vector<std::string>& path_segments, const DictionaryValue* const parameters, - const bool find_one_element) - : WebDriverCommand(path_segments, parameters), - find_one_element_(find_one_element) {} - virtual ~FindElementCommand() {} + const bool find_one_element); + virtual ~FindElementCommand(); virtual bool Init(Response* const response); - virtual bool DoesPost() { return true; } + virtual bool DoesPost(); virtual void ExecutePost(Response* const response); private: - virtual bool RequiresValidTab() { return false; } + virtual bool RequiresValidTab(); const bool find_one_element_; std::string root_element_id_; std::string use_; diff --git a/chrome/test/webdriver/keymap.cc b/chrome/test/webdriver/keymap.cc index e1c3fec..c3080d7 100644 --- a/chrome/test/webdriver/keymap.cc +++ b/chrome/test/webdriver/keymap.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -118,6 +118,8 @@ KeyMap::KeyMap() { shifted_keys_[L')'] = ui::VKEY_0; } +KeyMap::~KeyMap() {} + ui::KeyboardCode KeyMap::Get(const wchar_t& key) const { std::map<wchar_t, ui::KeyboardCode>::const_iterator it; it = keys_.find(key); diff --git a/chrome/test/webdriver/keymap.h b/chrome/test/webdriver/keymap.h index fab2bcc..3b98d54 100644 --- a/chrome/test/webdriver/keymap.h +++ b/chrome/test/webdriver/keymap.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -16,6 +16,7 @@ namespace webdriver { class KeyMap { public: KeyMap(); + ~KeyMap(); ui::KeyboardCode Get(const wchar_t& key) const; bool Press(const scoped_refptr<WindowProxy>& window, diff --git a/chrome/test/webdriver/session.cc b/chrome/test/webdriver/session.cc index 6c1b026e..00de26c 100644 --- a/chrome/test/webdriver/session.cc +++ b/chrome/test/webdriver/session.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -34,6 +34,8 @@ Session::Session(const std::string& id) current_frame_xpath_("") { } +Session::~Session() {} + bool Session::Init() { if (!thread_.Start()) { LOG(ERROR) << "Cannot start session thread"; diff --git a/chrome/test/webdriver/session.h b/chrome/test/webdriver/session.h index e716e19..8bc5cd5 100644 --- a/chrome/test/webdriver/session.h +++ b/chrome/test/webdriver/session.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,9 @@ #include "chrome/test/webdriver/automation.h" #include "chrome/test/webdriver/error_codes.h" +class ListValue; +class Value; + namespace base { class WaitableEvent; } @@ -25,6 +28,7 @@ namespace webdriver { class Session { public: explicit Session(const std::string& id); + ~Session(); // Creates a browser. bool Init(); diff --git a/chrome/test/webdriver/session_manager.cc b/chrome/test/webdriver/session_manager.cc index 0064737..30adf9e 100644 --- a/chrome/test/webdriver/session_manager.cc +++ b/chrome/test/webdriver/session_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -177,6 +177,10 @@ Session* SessionManager::GetSession(const std::string& id) const { return it->second; } +SessionManager::SessionManager() : addr_(""), port_(""), count_(0) {} + +SessionManager::~SessionManager() {} + // static SessionManager* SessionManager::GetInstance() { return Singleton<SessionManager>::get(); diff --git a/chrome/test/webdriver/session_manager.h b/chrome/test/webdriver/session_manager.h index c4f8729..959ff84 100644 --- a/chrome/test/webdriver/session_manager.h +++ b/chrome/test/webdriver/session_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -34,7 +34,8 @@ class SessionManager { Session* GetSession(const std::string& id) const; private: - SessionManager() : addr_(""), port_(""), count_(0) {} + SessionManager(); + ~SessionManager(); friend struct DefaultSingletonTraits<SessionManager>; std::string GenerateSessionID(); std::string IPLookup(const std::string& nic); diff --git a/webkit/mocks/mock_webframe.cc b/webkit/mocks/mock_webframe.cc new file mode 100644 index 0000000..cf382c3 --- /dev/null +++ b/webkit/mocks/mock_webframe.cc @@ -0,0 +1,393 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/mocks/mock_webframe.h" + +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" + +namespace webkit_glue { + +MockWebFrame::MockWebFrame() {} + +MockWebFrame::~MockWebFrame() {} + +WebString MockWebFrame::name() const { + return WebString(); +} + +void MockWebFrame::setName(const WebString&) {} + +long long MockWebFrame::identifier() const { + return 0; +} + +WebURL MockWebFrame::url() const { + return WebURL(); +} + +WebURL MockWebFrame::favIconURL() const { + return WebURL(); +} + +WebURL MockWebFrame::openSearchDescriptionURL() const { + return WebURL(); +} + +WebString MockWebFrame::encoding() const { + return WebString(); +} + +void MockWebFrame::setCanHaveScrollbars(bool) {} + +WebSize MockWebFrame::scrollOffset() const { + return WebSize(0,0); +} + +WebSize MockWebFrame::contentsSize() const { + return WebSize(); +} + +int MockWebFrame::contentsPreferredWidth() const { + return 0; +} + +int MockWebFrame::documentElementScrollHeight() const { + return 0; +} + +bool MockWebFrame::hasVisibleContent() const { + return false; +} + +WebView* MockWebFrame::view() const { + return NULL; +} + +WebFrame* MockWebFrame::opener() const { + return NULL; +} + +WebFrame* MockWebFrame::parent() const { + return NULL; +} + +WebFrame* MockWebFrame::top() const { + return NULL; +} + +WebFrame* MockWebFrame::firstChild() const { + return NULL; +} + +WebFrame* MockWebFrame::lastChild() const { + return NULL; +} + +WebFrame* MockWebFrame::nextSibling() const { + return NULL; +} + +WebFrame* MockWebFrame::previousSibling() const { + return NULL; +} + +WebFrame* MockWebFrame::traverseNext(bool wrap) const { + return NULL; +} + +WebFrame* MockWebFrame::traversePrevious(bool wrap) const { + return NULL; +} + +WebFrame* MockWebFrame::findChildByName(const WebString& name) const { + return NULL; +} + +WebFrame* MockWebFrame::findChildByExpression(const WebString& xpath) const { + return NULL; +} + +WebDocument MockWebFrame::document() const { + return WebDocument(); +} + +void MockWebFrame::forms(WebVector<WebFormElement>&) const {} + +WebAnimationController* MockWebFrame::animationController() { + return NULL; +} + +WebPerformance MockWebFrame::performance() const { + return WebPerformance(); +} + +WebSecurityOrigin MockWebFrame::securityOrigin() const { + return WebSecurityOrigin(); +} + +void MockWebFrame::grantUniversalAccess() {} + +NPObject* MockWebFrame::windowObject() const { + return NULL; +} + +void MockWebFrame::bindToWindowObject(const WebString& name, NPObject*) {} + +void MockWebFrame::executeScript(const WebScriptSource&) {} + +void MockWebFrame::executeScriptInIsolatedWorld( + int worldId, const WebScriptSource* sources, unsigned numSources, + int extensionGroup) {} + +void MockWebFrame::addMessageToConsole(const WebConsoleMessage&) {} + +void MockWebFrame::collectGarbage() {} + +#if WEBKIT_USING_V8 +v8::Handle<v8::Value> MockWebFrame::executeScriptAndReturnValue( + const WebScriptSource&) { + return v8::Handle<v8::Value>(); +} + +v8::Local<v8::Context> MockWebFrame::mainWorldScriptContext() const { + return v8::Local<v8::Context>(); +} +#endif + + +bool MockWebFrame::insertStyleText(const WebString& styleText, + const WebString& elementId) { + return false; +} + +void MockWebFrame::reload(bool ignoreCache) {} + +void MockWebFrame::loadRequest(const WebURLRequest&) {} + +void MockWebFrame::loadHistoryItem(const WebHistoryItem&) {} + +void MockWebFrame::loadData(const WebData& data, + const WebString& mimeType, + const WebString& textEncoding, + const WebURL& baseURL, + const WebURL& unreachableURL, + bool replace) {} + +void MockWebFrame::loadHTMLString(const WebData& html, + const WebURL& baseURL, + const WebURL& unreachableURL, + bool replace) {} + +bool MockWebFrame::isLoading() const { + return false; +} + +void MockWebFrame::stopLoading() {} + +WebKit::WebDataSource* MockWebFrame::provisionalDataSource() const { + return NULL; +} + +WebKit::WebDataSource* MockWebFrame::dataSource() const { + return NULL; +} + +WebHistoryItem MockWebFrame::previousHistoryItem() const { + return WebHistoryItem(); +} + +WebHistoryItem MockWebFrame::currentHistoryItem() const { + return WebHistoryItem(); +} + +void MockWebFrame::enableViewSourceMode(bool) {} + +bool MockWebFrame::isViewSourceModeEnabled() const { + return false; +} + +WebURLLoader* MockWebFrame::createAssociatedURLLoader() { + return NULL; +} + +void MockWebFrame::commitDocumentData(const char* data, size_t length) {} + +unsigned MockWebFrame::unloadListenerCount() const { + return 0; +} + +bool MockWebFrame::isProcessingUserGesture() const { + return false; +} + +bool MockWebFrame::willSuppressOpenerInNewFrame() const { + return false; +} + +void MockWebFrame::replaceSelection(const WebString& text) {} + +void MockWebFrame::insertText(const WebString& text) {} + +void MockWebFrame::setMarkedText(const WebString& text, + unsigned location, + unsigned length) {} + +void MockWebFrame::unmarkText() {} + +bool MockWebFrame::hasMarkedText() const { + return false; +} + +WebRange MockWebFrame::markedRange() const { + return WebRange(); +} + +bool MockWebFrame::firstRectForCharacterRange(unsigned location, + unsigned length, + WebRect&) const { + return false; +} + +bool MockWebFrame::executeCommand(const WebString&) { + return false; +} + +bool MockWebFrame::executeCommand(const WebString&, const WebString& value) { + return false; +} + +bool MockWebFrame::isCommandEnabled(const WebString&) const { + return false; +} + +void MockWebFrame::enableContinuousSpellChecking(bool) {} + +bool MockWebFrame::isContinuousSpellCheckingEnabled() const { + return false; +} + +bool MockWebFrame::hasSelection() const { + return false; +} + +WebRange MockWebFrame::selectionRange() const { + return WebRange(); +} + +WebString MockWebFrame::selectionAsText() const { + return WebString(); +} + +WebString MockWebFrame::selectionAsMarkup() const { + return WebString(); +} + +bool MockWebFrame::selectWordAroundCaret() { + return false; +} + +int MockWebFrame::printBegin(const WebSize& pageSize, + const WebNode& constrainToNode, + int printerDPI, + bool* useBrowserOverlays) { + return 0; +} + +float MockWebFrame::getPrintPageShrink(int page) { + return 0; +} + +float MockWebFrame::printPage(int pageToPrint, WebCanvas*) { + return 0; +} + +void MockWebFrame::printEnd() {} + +bool MockWebFrame::isPageBoxVisible(int pageIndex) { + return false; +} + +void MockWebFrame::pageSizeAndMarginsInPixels(int pageIndex, + WebSize& pageSize, + int& marginTop, + int& marginRight, + int& marginBottom, + int& marginLeft) {} + +bool MockWebFrame::find(int identifier, + const WebString& searchText, + const WebFindOptions& options, + bool wrapWithinFrame, + WebRect* selectionRect) { + return false; +} + +void MockWebFrame::stopFinding(bool clearSelection) {} + +void MockWebFrame::scopeStringMatches(int identifier, + const WebString& searchText, + const WebFindOptions& options, + bool reset) {} + +void MockWebFrame::cancelPendingScopingEffort() {} + +void MockWebFrame::increaseMatchCount(int count, int identifier) {} + +void MockWebFrame::resetMatchCount() {} + +bool MockWebFrame::registerPasswordListener( + WebInputElement, + WebPasswordAutocompleteListener*) { + return false; +} + +void MockWebFrame::notifiyPasswordListenerOfAutocomplete( + const WebInputElement&) {} + +WebString MockWebFrame::contentAsText(size_t maxChars) const { + return WebString(); +} + +WebString MockWebFrame::contentAsMarkup() const { + return WebString(); +} + +WebString MockWebFrame::renderTreeAsText() const { + return WebString(); +} + +WebString MockWebFrame::counterValueForElementById(const WebString& id) const { + return WebString(); +} + +WebString MockWebFrame::markerTextForListItem(const WebElement&) const { + return WebString(); +} + +int MockWebFrame::pageNumberForElementById(const WebString& id, + float pageWidthInPixels, + float pageHeightInPixels) const { + return 0; +} + +WebRect MockWebFrame::selectionBoundsRect() const { + return WebRect(); +} + +bool MockWebFrame::selectionStartHasSpellingMarkerFor(int from, + int length) const { + return false; +} + +bool MockWebFrame::pauseSVGAnimation(const WebString& animationId, + double time, + const WebString& elementId) { + return false; +} + +WebString MockWebFrame::layerTreeAsText() const { + return WebString(); +} + +} // namespace webkit_glue diff --git a/webkit/mocks/mock_webframe.h b/webkit/mocks/mock_webframe.h index bf65c5c..e49029d 100644 --- a/webkit/mocks/mock_webframe.h +++ b/webkit/mocks/mock_webframe.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -48,11 +48,8 @@ namespace webkit_glue { class MockWebFrame : public WebKit::WebFrame { public: - MockWebFrame() { - } - - virtual ~MockWebFrame() { - } + MockWebFrame(); + virtual ~MockWebFrame(); MOCK_METHOD2(setReferrerForRequest, void(WebURLRequest&, const WebURL&)); MOCK_METHOD1(dispatchWillSendRequest, void(WebURLRequest&)); @@ -65,286 +62,148 @@ class MockWebFrame : public WebKit::WebFrame { return NULL; } - virtual WebString name() const { - return WebString(); - } - virtual void setName(const WebString&) {} - virtual long long identifier() const { - return 0; - } - virtual WebURL url() const { - return WebURL(); - } - virtual WebURL favIconURL() const { - return WebURL(); - } - virtual WebURL openSearchDescriptionURL() const { - return WebURL(); - } - virtual WebString encoding() const { - return WebString(); - } - virtual void setCanHaveScrollbars(bool) {} - virtual WebSize scrollOffset() const { - return WebSize(0,0); - } - virtual WebSize contentsSize() const { - return WebSize(); - } - virtual int contentsPreferredWidth() const { - return 0; - } - virtual int documentElementScrollHeight() const { - return 0; - } - virtual bool hasVisibleContent() const { - return false; - } - virtual WebView* view() const { - return NULL; - } - virtual WebFrame* opener() const { - return NULL; - } - virtual WebFrame* parent() const { - return NULL; - } - virtual WebFrame* top() const { - return NULL; - } - virtual WebFrame* firstChild() const { - return NULL; - } - virtual WebFrame* lastChild() const { - return NULL; - } - virtual WebFrame* nextSibling() const { - return NULL; - } - virtual WebFrame* previousSibling() const { - return NULL; - } - virtual WebFrame* traverseNext(bool wrap) const { - return NULL; - } - virtual WebFrame* traversePrevious(bool wrap) const { - return NULL; - } - virtual WebFrame* findChildByName(const WebString& name) const { - return NULL; - } - virtual WebFrame* findChildByExpression(const WebString& xpath) const { - return NULL; - } - virtual WebDocument document() const { - return WebDocument(); - } - virtual void forms(WebVector<WebFormElement>&) const {} - virtual WebAnimationController* animationController() { - return NULL; - } - virtual WebPerformance performance() const { - return WebPerformance(); - } - virtual WebSecurityOrigin securityOrigin() const { - return WebSecurityOrigin(); - } - virtual void grantUniversalAccess() {} - virtual NPObject* windowObject() const { - return NULL; - } - virtual void bindToWindowObject(const WebString& name, NPObject*) {} - virtual void executeScript(const WebScriptSource&) {} + virtual WebString name() const; + virtual void setName(const WebString&); + virtual long long identifier() const; + virtual WebURL url() const; + virtual WebURL favIconURL() const; + virtual WebURL openSearchDescriptionURL() const; + virtual WebString encoding() const; + virtual void setCanHaveScrollbars(bool); + virtual WebSize scrollOffset() const; + virtual WebSize contentsSize() const; + virtual int contentsPreferredWidth() const; + virtual int documentElementScrollHeight() const; + virtual bool hasVisibleContent() const; + virtual WebView* view() const; + virtual WebFrame* opener() const; + virtual WebFrame* parent() const; + virtual WebFrame* top() const; + virtual WebFrame* firstChild() const; + virtual WebFrame* lastChild() const; + virtual WebFrame* nextSibling() const; + virtual WebFrame* previousSibling() const; + virtual WebFrame* traverseNext(bool wrap) const; + virtual WebFrame* traversePrevious(bool wrap) const; + virtual WebFrame* findChildByName(const WebString& name) const; + virtual WebFrame* findChildByExpression(const WebString& xpath) const; + virtual WebDocument document() const; + virtual void forms(WebVector<WebFormElement>&) const; + virtual WebAnimationController* animationController(); + virtual WebPerformance performance() const; + virtual WebSecurityOrigin securityOrigin() const; + virtual void grantUniversalAccess(); + virtual NPObject* windowObject() const; + virtual void bindToWindowObject(const WebString& name, NPObject*); + virtual void executeScript(const WebScriptSource&); virtual void executeScriptInIsolatedWorld( int worldId, const WebScriptSource* sources, unsigned numSources, - int extensionGroup) {} - virtual void addMessageToConsole(const WebConsoleMessage&) {} - virtual void collectGarbage() {} + int extensionGroup); + virtual void addMessageToConsole(const WebConsoleMessage&); + virtual void collectGarbage(); #if WEBKIT_USING_V8 virtual v8::Handle<v8::Value> executeScriptAndReturnValue( - const WebScriptSource&) { - return v8::Handle<v8::Value>(); - } - virtual v8::Local<v8::Context> mainWorldScriptContext() const { - return v8::Local<v8::Context>(); - } + const WebScriptSource&); + virtual v8::Local<v8::Context> mainWorldScriptContext() const; #endif virtual bool insertStyleText(const WebString& styleText, - const WebString& elementId) { - return false; - } - virtual void reload(bool ignoreCache = false) {} - virtual void loadRequest(const WebURLRequest&) {} - virtual void loadHistoryItem(const WebHistoryItem&) {} + const WebString& elementId); + virtual void reload(bool ignoreCache = false); + virtual void loadRequest(const WebURLRequest&); + virtual void loadHistoryItem(const WebHistoryItem&); virtual void loadData(const WebData& data, const WebString& mimeType, const WebString& textEncoding, const WebURL& baseURL, const WebURL& unreachableURL = WebURL(), - bool replace = false) {} + bool replace = false); virtual void loadHTMLString(const WebData& html, const WebURL& baseURL, const WebURL& unreachableURL = WebURL(), - bool replace = false) {} - virtual bool isLoading() const { - return false; - } - virtual void stopLoading() {} - virtual WebKit::WebDataSource* provisionalDataSource() const { - return NULL; - } - virtual WebKit::WebDataSource* dataSource() const { - return NULL; - } - virtual WebHistoryItem previousHistoryItem() const { - return WebHistoryItem(); - } - virtual WebHistoryItem currentHistoryItem() const { - return WebHistoryItem(); - } - virtual void enableViewSourceMode(bool) {} - virtual bool isViewSourceModeEnabled() const { - return false; - } + bool replace = false); + virtual bool isLoading() const; + virtual void stopLoading(); + virtual WebKit::WebDataSource* provisionalDataSource() const; + virtual WebKit::WebDataSource* dataSource() const; + virtual WebHistoryItem previousHistoryItem() const; + virtual WebHistoryItem currentHistoryItem() const; + virtual void enableViewSourceMode(bool); + virtual bool isViewSourceModeEnabled() const; // The next two methods were mocked above. // virtual void setReferrerForRequest(WebURLRequest&, const WebURL&) {} // virtual void dispatchWillSendRequest(WebURLRequest&) {} - virtual WebURLLoader* createAssociatedURLLoader() { - return NULL; - } - virtual void commitDocumentData(const char* data, size_t length) {} - virtual unsigned unloadListenerCount() const { - return 0; - } - virtual bool isProcessingUserGesture() const { - return false; - } - virtual bool willSuppressOpenerInNewFrame() const { - return false; - } - virtual void replaceSelection(const WebString& text) {} - virtual void insertText(const WebString& text) {} + virtual WebURLLoader* createAssociatedURLLoader(); + virtual void commitDocumentData(const char* data, size_t length); + virtual unsigned unloadListenerCount() const; + virtual bool isProcessingUserGesture() const; + virtual bool willSuppressOpenerInNewFrame() const; + virtual void replaceSelection(const WebString& text); + virtual void insertText(const WebString& text); virtual void setMarkedText(const WebString& text, unsigned location, - unsigned length) {} - virtual void unmarkText() {} - virtual bool hasMarkedText() const { - return false; - } - virtual WebRange markedRange() const { - return WebRange(); - } + unsigned length); + virtual void unmarkText(); + virtual bool hasMarkedText() const; + virtual WebRange markedRange() const; virtual bool firstRectForCharacterRange(unsigned location, unsigned length, - WebRect&) const { - return false; - } - virtual bool executeCommand(const WebString&) { - return false; - } - virtual bool executeCommand(const WebString&, const WebString& value) { - return false; - } - virtual bool isCommandEnabled(const WebString&) const { - return false; - } - virtual void enableContinuousSpellChecking(bool) {} - virtual bool isContinuousSpellCheckingEnabled() const { - return false; - } - virtual bool hasSelection() const { - return false; - } - virtual WebRange selectionRange() const { - return WebRange(); - } - virtual WebString selectionAsText() const { - return WebString(); - } - virtual WebString selectionAsMarkup() const { - return WebString(); - } - virtual bool selectWordAroundCaret() { - return false; - } + WebRect&) const; + virtual bool executeCommand(const WebString&); + virtual bool executeCommand(const WebString&, const WebString& value); + virtual bool isCommandEnabled(const WebString&) const; + virtual void enableContinuousSpellChecking(bool); + virtual bool isContinuousSpellCheckingEnabled() const; + virtual bool hasSelection() const; + virtual WebRange selectionRange() const; + virtual WebString selectionAsText() const; + virtual WebString selectionAsMarkup() const; + virtual bool selectWordAroundCaret(); virtual int printBegin(const WebSize& pageSize, const WebNode& constrainToNode, int printerDPI = 72, - bool* useBrowserOverlays = 0) { - return 0; - } - virtual float getPrintPageShrink(int page) { - return 0; - } - virtual float printPage(int pageToPrint, WebCanvas*) { - return 0; - } - virtual void printEnd() {} - virtual bool isPageBoxVisible(int pageIndex) { - return false; - } + bool* useBrowserOverlays = 0); + virtual float getPrintPageShrink(int page); + virtual float printPage(int pageToPrint, WebCanvas*); + virtual void printEnd(); + virtual bool isPageBoxVisible(int pageIndex); virtual void pageSizeAndMarginsInPixels(int pageIndex, WebSize& pageSize, int& marginTop, int& marginRight, int& marginBottom, - int& marginLeft) {} + int& marginLeft); virtual bool find(int identifier, const WebString& searchText, const WebFindOptions& options, bool wrapWithinFrame, - WebRect* selectionRect) { - return false; - } - virtual void stopFinding(bool clearSelection) {} + WebRect* selectionRect); + virtual void stopFinding(bool clearSelection); virtual void scopeStringMatches(int identifier, const WebString& searchText, const WebFindOptions& options, - bool reset) {} - virtual void cancelPendingScopingEffort() {} - virtual void increaseMatchCount(int count, int identifier) {} - virtual void resetMatchCount() {} + bool reset); + virtual void cancelPendingScopingEffort(); + virtual void increaseMatchCount(int count, int identifier); + virtual void resetMatchCount(); virtual bool registerPasswordListener( WebInputElement, - WebPasswordAutocompleteListener*) { - return false; - } + WebPasswordAutocompleteListener*); virtual void notifiyPasswordListenerOfAutocomplete( - const WebInputElement&) {} - virtual WebString contentAsText(size_t maxChars) const { - return WebString(); - } - virtual WebString contentAsMarkup() const { - return WebString(); - } - virtual WebString renderTreeAsText() const { - return WebString(); - } - virtual WebString counterValueForElementById(const WebString& id) const { - return WebString(); - } - virtual WebString markerTextForListItem(const WebElement&) const { - return WebString(); - } + const WebInputElement&); + virtual WebString contentAsText(size_t maxChars) const; + virtual WebString contentAsMarkup() const; + virtual WebString renderTreeAsText() const; + virtual WebString counterValueForElementById(const WebString& id) const; + virtual WebString markerTextForListItem(const WebElement&) const; virtual int pageNumberForElementById(const WebString& id, float pageWidthInPixels, - float pageHeightInPixels) const { - return 0; - } - virtual WebRect selectionBoundsRect() const { - return WebRect(); - } - virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const { - return false; - } + float pageHeightInPixels) const; + virtual WebRect selectionBoundsRect() const; + virtual bool selectionStartHasSpellingMarkerFor(int from, int length) const; virtual bool pauseSVGAnimation(const WebString& animationId, double time, - const WebString& elementId) { - return false; - } - virtual WebString layerTreeAsText() const { - return WebString(); - } + const WebString& elementId); + virtual WebString layerTreeAsText() const; private: DISALLOW_COPY_AND_ASSIGN(MockWebFrame); diff --git a/webkit/mocks/mock_weburlloader.cc b/webkit/mocks/mock_weburlloader.cc new file mode 100644 index 0000000..7610c19 --- /dev/null +++ b/webkit/mocks/mock_weburlloader.cc @@ -0,0 +1,18 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/mocks/mock_weburlloader.h" + +#include "third_party/WebKit/Source/WebKit/chromium/public/WebData.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" + +namespace webkit_glue { + +MockWebURLLoader::MockWebURLLoader() {} + +MockWebURLLoader::~MockWebURLLoader() {} + +} // namespace webkit_glue diff --git a/webkit/mocks/mock_weburlloader.h b/webkit/mocks/mock_weburlloader.h index 7253faa..68ff9a2 100644 --- a/webkit/mocks/mock_weburlloader.h +++ b/webkit/mocks/mock_weburlloader.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,11 +12,8 @@ namespace webkit_glue { class MockWebURLLoader : public WebKit::WebURLLoader { public: - MockWebURLLoader() { - } - - virtual ~MockWebURLLoader() { - } + MockWebURLLoader(); + virtual ~MockWebURLLoader(); MOCK_METHOD4(loadSynchronously, void(const WebKit::WebURLRequest& request, WebKit::WebURLResponse& response, diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 6a2d336..159fc68 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -403,7 +403,9 @@ '../../glue/webpasswordautocompletelistener_unittest.cc', '../../glue/webview_unittest.cc', '../../mocks/mock_resource_loader_bridge.h', + '../../mocks/mock_webframe.cc', '../../mocks/mock_webframe.h', + '../../mocks/mock_weburlloader.cc', '../../mocks/mock_weburlloader.h', '../../plugins/npapi/plugin_group_unittest.cc', '../../plugins/npapi/plugin_lib_unittest.cc', |