Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/ui/bookmarks/recently_used_folders_combo_model_unittest.cc

Issue 2799883003: Switch from TestBrowserThread to TestBrowserThreadBundle in chrome. (Closed)
Patch Set: fix-string Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/bookmarks/recently_used_folders_combo_model.h" 5 #include "chrome/browser/ui/bookmarks/recently_used_folders_combo_model.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
12 #include "components/bookmarks/browser/bookmark_model.h" 11 #include "components/bookmarks/browser/bookmark_model.h"
13 #include "components/bookmarks/test/bookmark_test_helpers.h" 12 #include "components/bookmarks/test/bookmark_test_helpers.h"
14 #include "components/bookmarks/test/test_bookmark_client.h" 13 #include "components/bookmarks/test/test_bookmark_client.h"
15 #include "content/public/test/test_browser_thread.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/base/models/combobox_model_observer.h" 16 #include "ui/base/models/combobox_model_observer.h"
18 17
19 using bookmarks::BookmarkModel; 18 using bookmarks::BookmarkModel;
20 using bookmarks::BookmarkNode; 19 using bookmarks::BookmarkNode;
21 using bookmarks::TestBookmarkClient; 20 using bookmarks::TestBookmarkClient;
22 using content::BrowserThread;
23
24 // Implementation of ComboboxModelObserver that records when 21 // Implementation of ComboboxModelObserver that records when
25 // OnComboboxModelChanged() is invoked. 22 // OnComboboxModelChanged() is invoked.
26 class TestComboboxModelObserver : public ui::ComboboxModelObserver { 23 class TestComboboxModelObserver : public ui::ComboboxModelObserver {
27 public: 24 public:
28 TestComboboxModelObserver() : changed_(false) {} 25 TestComboboxModelObserver() : changed_(false) {}
29 ~TestComboboxModelObserver() override {} 26 ~TestComboboxModelObserver() override {}
30 27
31 // Returns whether the model changed and clears changed state. 28 // Returns whether the model changed and clears changed state.
32 bool GetAndClearChanged() { 29 bool GetAndClearChanged() {
33 const bool changed = changed_; 30 const bool changed = changed_;
34 changed_ = false; 31 changed_ = false;
35 return changed; 32 return changed;
36 } 33 }
37 34
38 // ui::ComboboxModelObserver: 35 // ui::ComboboxModelObserver:
39 void OnComboboxModelChanged(ui::ComboboxModel* model) override { 36 void OnComboboxModelChanged(ui::ComboboxModel* model) override {
40 changed_ = true; 37 changed_ = true;
41 } 38 }
42 39
43 private: 40 private:
44 bool changed_; 41 bool changed_;
45 42
46 DISALLOW_COPY_AND_ASSIGN(TestComboboxModelObserver); 43 DISALLOW_COPY_AND_ASSIGN(TestComboboxModelObserver);
47 }; 44 };
48 45
49 class RecentlyUsedFoldersComboModelTest : public testing::Test { 46 class RecentlyUsedFoldersComboModelTest : public testing::Test {
50 public: 47 public:
51 RecentlyUsedFoldersComboModelTest(); 48 RecentlyUsedFoldersComboModelTest() = default;
52 49
53 private: 50 private:
54 base::MessageLoopForUI message_loop_; 51 content::TestBrowserThreadBundle test_browser_thread_bundle_;
55 content::TestBrowserThread ui_thread_;
56 content::TestBrowserThread file_thread_;
57 52
58 DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModelTest); 53 DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModelTest);
59 }; 54 };
60 55
61 RecentlyUsedFoldersComboModelTest::RecentlyUsedFoldersComboModelTest()
62 : ui_thread_(BrowserThread::UI, &message_loop_),
63 file_thread_(BrowserThread::FILE, &message_loop_) {
64 }
65
66 // Verifies there are no duplicate nodes in the model. 56 // Verifies there are no duplicate nodes in the model.
67 TEST_F(RecentlyUsedFoldersComboModelTest, NoDups) { 57 TEST_F(RecentlyUsedFoldersComboModelTest, NoDups) {
68 std::unique_ptr<BookmarkModel> bookmark_model( 58 std::unique_ptr<BookmarkModel> bookmark_model(
69 TestBookmarkClient::CreateModel()); 59 TestBookmarkClient::CreateModel());
70 const BookmarkNode* new_node = bookmark_model->AddURL( 60 const BookmarkNode* new_node = bookmark_model->AddURL(
71 bookmark_model->bookmark_bar_node(), 0, base::ASCIIToUTF16("a"), 61 bookmark_model->bookmark_bar_node(), 0, base::ASCIIToUTF16("a"),
72 GURL("http://a")); 62 GURL("http://a"));
73 RecentlyUsedFoldersComboModel model(bookmark_model.get(), new_node); 63 RecentlyUsedFoldersComboModel model(bookmark_model.get(), new_node);
74 std::set<base::string16> items; 64 std::set<base::string16> items;
75 for (int i = 0; i < model.GetItemCount(); ++i) { 65 for (int i = 0; i < model.GetItemCount(); ++i) {
(...skipping 23 matching lines...) Expand all
99 const int updated_count = model.GetItemCount(); 89 const int updated_count = model.GetItemCount();
100 EXPECT_LT(updated_count, initial_count); 90 EXPECT_LT(updated_count, initial_count);
101 91
102 // Remove all, which should remove a folder too. 92 // Remove all, which should remove a folder too.
103 bookmark_model->RemoveAllUserBookmarks(); 93 bookmark_model->RemoveAllUserBookmarks();
104 EXPECT_TRUE(observer.GetAndClearChanged()); 94 EXPECT_TRUE(observer.GetAndClearChanged());
105 EXPECT_LT(model.GetItemCount(), updated_count); 95 EXPECT_LT(model.GetItemCount(), updated_count);
106 96
107 model.RemoveObserver(&observer); 97 model.RemoveObserver(&observer);
108 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698