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

Side by Side Diff: chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 years, 6 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 | Annotate | Revision Log
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/toolbar/back_forward_menu_model.h" 5 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/string16.h" 8 #include "base/string16.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/favicon/favicon_service_factory.h" 12 #include "chrome/browser/favicon/favicon_service_factory.h"
13 #include "chrome/browser/history/history_service.h" 13 #include "chrome/browser/history/history_service.h"
14 #include "chrome/browser/history/history_service_factory.h" 14 #include "chrome/browser/history/history_service_factory.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_tabstrip.h" 17 #include "chrome/browser/ui/browser_tabstrip.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
21 #include "chrome/test/base/test_browser_window.h" 21 #include "chrome/test/base/test_browser_window.h"
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/navigation_entry.h" 24 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/test_browser_thread.h"
27 #include "content/public/test/web_contents_tester.h" 26 #include "content/public/test/web_contents_tester.h"
28 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
29 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
30 #include "ui/gfx/codec/png_codec.h" 29 #include "ui/gfx/codec/png_codec.h"
31 30
32 using content::BrowserThread;
33 using content::WebContentsTester; 31 using content::WebContentsTester;
34 32
35 namespace { 33 namespace {
36 34
37 // Creates a bitmap of the specified color. 35 // Creates a bitmap of the specified color.
38 SkBitmap CreateBitmap(SkColor color) { 36 SkBitmap CreateBitmap(SkColor color) {
39 SkBitmap bitmap; 37 SkBitmap bitmap;
40 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16); 38 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
41 bitmap.allocPixels(); 39 bitmap.allocPixels();
42 bitmap.eraseColor(color); 40 bitmap.eraseColor(color);
(...skipping 14 matching lines...) Expand all
57 private: 55 private:
58 bool was_called_; 56 bool was_called_;
59 57
60 DISALLOW_COPY_AND_ASSIGN(FaviconDelegate); 58 DISALLOW_COPY_AND_ASSIGN(FaviconDelegate);
61 }; 59 };
62 60
63 } // namespace 61 } // namespace
64 62
65 class BackFwdMenuModelTest : public ChromeRenderViewHostTestHarness { 63 class BackFwdMenuModelTest : public ChromeRenderViewHostTestHarness {
66 public: 64 public:
67 BackFwdMenuModelTest()
68 : ui_thread_(BrowserThread::UI, &message_loop_) {
69 }
70
71 void ValidateModel(BackForwardMenuModel* model, int history_items, 65 void ValidateModel(BackForwardMenuModel* model, int history_items,
72 int chapter_stops) { 66 int chapter_stops) {
73 int h = std::min(BackForwardMenuModel::kMaxHistoryItems, history_items); 67 int h = std::min(BackForwardMenuModel::kMaxHistoryItems, history_items);
74 int c = std::min(BackForwardMenuModel::kMaxChapterStops, chapter_stops); 68 int c = std::min(BackForwardMenuModel::kMaxChapterStops, chapter_stops);
75 EXPECT_EQ(h, model->GetHistoryItemCount()); 69 EXPECT_EQ(h, model->GetHistoryItemCount());
76 EXPECT_EQ(c, model->GetChapterStopCount(h)); 70 EXPECT_EQ(c, model->GetChapterStopCount(h));
77 if (h > 0) 71 if (h > 0)
78 h += 2; // Separator and View History link. 72 h += 2; // Separator and View History link.
79 if (c > 0) 73 if (c > 0)
80 ++c; 74 ++c;
(...skipping 20 matching lines...) Expand all
101 95
102 // Goes back/forward and commits the load. 96 // Goes back/forward and commits the load.
103 void GoBack() { 97 void GoBack() {
104 controller().GoBack(); 98 controller().GoBack();
105 WebContentsTester::For(web_contents())->CommitPendingNavigation(); 99 WebContentsTester::For(web_contents())->CommitPendingNavigation();
106 } 100 }
107 void GoForward() { 101 void GoForward() {
108 controller().GoForward(); 102 controller().GoForward();
109 WebContentsTester::For(web_contents())->CommitPendingNavigation(); 103 WebContentsTester::For(web_contents())->CommitPendingNavigation();
110 } 104 }
111
112 content::TestBrowserThread ui_thread_;
113 }; 105 };
114 106
115 TEST_F(BackFwdMenuModelTest, BasicCase) { 107 TEST_F(BackFwdMenuModelTest, BasicCase) {
116 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel( 108 scoped_ptr<BackForwardMenuModel> back_model(new BackForwardMenuModel(
117 NULL, BackForwardMenuModel::BACKWARD_MENU)); 109 NULL, BackForwardMenuModel::BACKWARD_MENU));
118 back_model->set_test_web_contents(web_contents()); 110 back_model->set_test_web_contents(web_contents());
119 111
120 scoped_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel( 112 scoped_ptr<BackForwardMenuModel> forward_model(new BackForwardMenuModel(
121 NULL, BackForwardMenuModel::FORWARD_MENU)); 113 NULL, BackForwardMenuModel::FORWARD_MENU));
122 forward_model->set_test_web_contents(web_contents()); 114 forward_model->set_test_web_contents(web_contents());
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // Verify we did get the expected favicon. 559 // Verify we did get the expected favicon.
568 EXPECT_EQ(0, memcmp(new_icon_bitmap.getPixels(), 560 EXPECT_EQ(0, memcmp(new_icon_bitmap.getPixels(),
569 valid_icon_bitmap.getPixels(), 561 valid_icon_bitmap.getPixels(),
570 new_icon_bitmap.getSize())); 562 new_icon_bitmap.getSize()));
571 563
572 // Make sure the browser deconstructor doesn't have problems. 564 // Make sure the browser deconstructor doesn't have problems.
573 browser->tab_strip_model()->CloseAllTabs(); 565 browser->tab_strip_model()->CloseAllTabs();
574 // This is required to prevent the message loop from hanging. 566 // This is required to prevent the message loop from hanging.
575 profile()->DestroyHistoryService(); 567 profile()->DestroyHistoryService();
576 } 568 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/tabs/tab_strip_model_unittest.cc ('k') | chrome/browser/ui/website_settings/website_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698