Commit 4c9e5f1a authored by tfarina@chromium.org's avatar tfarina@chromium.org

bookmarks: Componentize bookmark_model_unittest.cc.

Few changes involved:

1) Using TestBookmarkClient to create BookmarkModel.
2) Removes unnecessary TestBrowserThreadBundle
3) With the above changes TestingProfile and BookmarkModelFactory
goes away.

BUG=367834
TEST=components_unittests --gtest_filter=BookmarkModel*
R=blundell@chromium.org, sdefresne@chromium.org

Review URL: https://codereview.chromium.org/291503007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271064 0039d316-1c4b-4281-b951-d872f2087c98
parent 446b23d7
...@@ -605,7 +605,6 @@ ...@@ -605,7 +605,6 @@
'browser/background/background_contents_service_unittest.cc', 'browser/background/background_contents_service_unittest.cc',
'browser/background/background_mode_manager_unittest.cc', 'browser/background/background_mode_manager_unittest.cc',
'browser/bookmarks/bookmark_html_writer_unittest.cc', 'browser/bookmarks/bookmark_html_writer_unittest.cc',
'browser/bookmarks/bookmark_model_unittest.cc',
'browser/browser_about_handler_unittest.cc', 'browser/browser_about_handler_unittest.cc',
'browser/browser_commands_unittest.cc', 'browser/browser_commands_unittest.cc',
'browser/browsing_data/browsing_data_appcache_helper_unittest.cc', 'browser/browsing_data/browsing_data_appcache_helper_unittest.cc',
......
...@@ -19,13 +19,10 @@ ...@@ -19,13 +19,10 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/core/browser/bookmark_model_observer.h" #include "components/bookmarks/core/browser/bookmark_model_observer.h"
#include "components/bookmarks/core/browser/bookmark_utils.h" #include "components/bookmarks/core/browser/bookmark_utils.h"
#include "components/bookmarks/core/test/bookmark_test_helpers.h" #include "components/bookmarks/core/test/bookmark_test_helpers.h"
#include "components/bookmarks/core/test/test_bookmark_client.h" #include "components/bookmarks/core/test/test_bookmark_client.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/models/tree_node_iterator.h" #include "ui/base/models/tree_node_iterator.h"
#include "ui/base/models/tree_node_model.h" #include "ui/base/models/tree_node_model.h"
...@@ -899,13 +896,7 @@ void PopulateBookmarkNode(TestNode* parent, ...@@ -899,13 +896,7 @@ void PopulateBookmarkNode(TestNode* parent,
// Test class that creates a BookmarkModel with a real history backend. // Test class that creates a BookmarkModel with a real history backend.
class BookmarkModelTestWithProfile : public testing::Test { class BookmarkModelTestWithProfile : public testing::Test {
public: public:
BookmarkModelTestWithProfile() BookmarkModelTestWithProfile() {}
: bb_model_(NULL) {}
// testing::Test:
virtual void TearDown() OVERRIDE {
profile_.reset(NULL);
}
protected: protected:
// Verifies the contents of the bookmark bar node match the contents of the // Verifies the contents of the bookmark bar node match the contents of the
...@@ -936,17 +927,8 @@ class BookmarkModelTestWithProfile : public testing::Test { ...@@ -936,17 +927,8 @@ class BookmarkModelTestWithProfile : public testing::Test {
ASSERT_TRUE(ids.insert(it.Next()->id()).second); ASSERT_TRUE(ids.insert(it.Next()->id()).second);
} }
void BlockTillBookmarkModelLoaded() { test::TestBookmarkClient client_;
bb_model_ = BookmarkModelFactory::GetForProfile(profile_.get()); scoped_ptr<BookmarkModel> model_;
test::WaitForBookmarkModelToLoad(bb_model_);
}
// The profile.
scoped_ptr<TestingProfile> profile_;
BookmarkModel* bb_model_;
private:
content::TestBrowserThreadBundle thread_bundle_;
}; };
// Creates a set of nodes in the bookmark bar model, then recreates the // Creates a set of nodes in the bookmark bar model, then recreates the
...@@ -970,34 +952,24 @@ TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) { ...@@ -970,34 +952,24 @@ TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) {
{ "a b c [ d e [ f ] ]", "g h i [ j k [ l ] ]"}, { "a b c [ d e [ f ] ]", "g h i [ j k [ l ] ]"},
}; };
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) {
// Recreate the profile. We need to reset with NULL first so that the last model_ = client_.CreateModel(false);
// HistoryService releases the locks on the files it creates and we can
// delete them.
profile_.reset(NULL);
profile_.reset(new TestingProfile());
profile_->CreateBookmarkModel(true);
ASSERT_TRUE(profile_->CreateHistoryService(true, false));
BlockTillBookmarkModelLoaded();
TestNode bbn; TestNode bbn;
PopulateNodeFromString(data[i].bbn_contents, &bbn); PopulateNodeFromString(data[i].bbn_contents, &bbn);
PopulateBookmarkNode(&bbn, bb_model_, bb_model_->bookmark_bar_node()); PopulateBookmarkNode(&bbn, model_.get(), model_->bookmark_bar_node());
TestNode other; TestNode other;
PopulateNodeFromString(data[i].other_contents, &other); PopulateNodeFromString(data[i].other_contents, &other);
PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node()); PopulateBookmarkNode(&other, model_.get(), model_->other_node());
TestNode mobile; TestNode mobile;
PopulateNodeFromString(data[i].mobile_contents, &mobile); PopulateNodeFromString(data[i].mobile_contents, &mobile);
PopulateBookmarkNode(&mobile, bb_model_, bb_model_->mobile_node()); PopulateBookmarkNode(&mobile, model_.get(), model_->mobile_node());
profile_->CreateBookmarkModel(false);
BlockTillBookmarkModelLoaded();
VerifyModelMatchesNode(&bbn, bb_model_->bookmark_bar_node()); VerifyModelMatchesNode(&bbn, model_->bookmark_bar_node());
VerifyModelMatchesNode(&other, bb_model_->other_node()); VerifyModelMatchesNode(&other, model_->other_node());
VerifyModelMatchesNode(&mobile, bb_model_->mobile_node()); VerifyModelMatchesNode(&mobile, model_->mobile_node());
VerifyNoDuplicateIDs(bb_model_); VerifyNoDuplicateIDs(model_.get());
} }
} }
......
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
'bookmarks/core/browser/bookmark_codec_unittest.cc', 'bookmarks/core/browser/bookmark_codec_unittest.cc',
'bookmarks/core/browser/bookmark_expanded_state_tracker_unittest.cc', 'bookmarks/core/browser/bookmark_expanded_state_tracker_unittest.cc',
'bookmarks/core/browser/bookmark_index_unittest.cc', 'bookmarks/core/browser/bookmark_index_unittest.cc',
'bookmarks/core/browser/bookmark_model_unittest.cc',
'bookmarks/core/browser/bookmark_utils_unittest.cc', 'bookmarks/core/browser/bookmark_utils_unittest.cc',
'captive_portal/captive_portal_detector_unittest.cc', 'captive_portal/captive_portal_detector_unittest.cc',
'cloud_devices/common/cloud_devices_urls_unittest.cc', 'cloud_devices/common/cloud_devices_urls_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment