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

Side by Side Diff: chrome/browser/ui/views/toolbar/reload_button_unittest.cc

Issue 1492423003: Rejigger ThemeService: move exposure of ThemeProvider interface to a (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix that unittest Created 5 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "chrome/browser/ui/views/toolbar/reload_button.h" 6 #include "chrome/browser/ui/views/toolbar/reload_button.h"
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
8 #include "chrome/test/base/testing_profile.h"
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/events/event_utils.h" 10 #include "ui/events/event_utils.h"
9 11
10 class ReloadButtonTest : public testing::Test { 12 class ReloadButtonTest : public ChromeRenderViewHostTestHarness {
11 public: 13 public:
12 ReloadButtonTest(); 14 ReloadButtonTest();
13 15
14 void CheckState(bool enabled, 16 void CheckState(bool enabled,
15 ReloadButton::Mode intended_mode, 17 ReloadButton::Mode intended_mode,
16 ReloadButton::Mode visible_mode, 18 ReloadButton::Mode visible_mode,
17 bool double_click_timer_running, 19 bool double_click_timer_running,
18 bool stop_to_reload_timer_running); 20 bool stop_to_reload_timer_running);
19 21
20 // These accessors eliminate the need to declare each testcase as a friend. 22 // These accessors eliminate the need to declare each testcase as a friend.
21 void set_mouse_hovered(bool hovered) { 23 void set_mouse_hovered(bool hovered) {
22 reload_.testing_mouse_hovered_ = hovered; 24 reload_.testing_mouse_hovered_ = hovered;
23 } 25 }
24 int reload_count() { return reload_.testing_reload_count_; } 26 int reload_count() { return reload_.testing_reload_count_; }
25 27
26 protected: 28 protected:
27 // We need a message loop for the timers to post events.
28 base::MessageLoop loop_;
29
30 ReloadButton reload_; 29 ReloadButton reload_;
31 }; 30 };
32 31
33 ReloadButtonTest::ReloadButtonTest() : reload_(NULL) { 32 ReloadButtonTest::ReloadButtonTest() : reload_(profile(), nullptr) {
34 // Set the timer delays to 0 so that timers will fire as soon as we tell the 33 // Set the timer delays to 0 so that timers will fire as soon as we tell the
35 // message loop to run pending tasks. 34 // message loop to run pending tasks.
36 reload_.double_click_timer_delay_ = base::TimeDelta(); 35 reload_.double_click_timer_delay_ = base::TimeDelta();
37 reload_.stop_to_reload_timer_delay_ = base::TimeDelta(); 36 reload_.stop_to_reload_timer_delay_ = base::TimeDelta();
38 } 37 }
39 38
40 void ReloadButtonTest::CheckState(bool enabled, 39 void ReloadButtonTest::CheckState(bool enabled,
41 ReloadButton::Mode intended_mode, 40 ReloadButton::Mode intended_mode,
42 ReloadButton::Mode visible_mode, 41 ReloadButton::Mode visible_mode,
43 bool double_click_timer_running, 42 bool double_click_timer_running,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 EXPECT_EQ(original_reload_count, reload_count()); 90 EXPECT_EQ(original_reload_count, reload_count());
92 91
93 // Hover the button, and change mode. The visible mode should not change, 92 // Hover the button, and change mode. The visible mode should not change,
94 // again because the timer is running. 93 // again because the timer is running.
95 set_mouse_hovered(true); 94 set_mouse_hovered(true);
96 reload_.ChangeMode(ReloadButton::MODE_STOP, false); 95 reload_.ChangeMode(ReloadButton::MODE_STOP, false);
97 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true, 96 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true,
98 false); 97 false);
99 98
100 // Now fire the timer. This should complete the mode change. 99 // Now fire the timer. This should complete the mode change.
101 loop_.RunUntilIdle(); 100 base::MessageLoop::current()->RunUntilIdle();
102 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, 101 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false,
103 false); 102 false);
104 } 103 }
105 104
106 TEST_F(ReloadButtonTest, DisableOnHover) { 105 TEST_F(ReloadButtonTest, DisableOnHover) {
107 // Change to stop and hover. 106 // Change to stop and hover.
108 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 107 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
109 ui::EventTimeForNow(), 0, 0); 108 ui::EventTimeForNow(), 0, 0);
110 reload_.ButtonPressed(&reload_, e); 109 reload_.ButtonPressed(&reload_, e);
111 reload_.ChangeMode(ReloadButton::MODE_STOP, false); 110 reload_.ChangeMode(ReloadButton::MODE_STOP, false);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 TEST_F(ReloadButtonTest, ResetOnTimer) { 143 TEST_F(ReloadButtonTest, ResetOnTimer) {
145 // Change to stop, hover, and change back to reload. 144 // Change to stop, hover, and change back to reload.
146 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 145 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
147 ui::EventTimeForNow(), 0, 0); 146 ui::EventTimeForNow(), 0, 0);
148 reload_.ButtonPressed(&reload_, e); 147 reload_.ButtonPressed(&reload_, e);
149 reload_.ChangeMode(ReloadButton::MODE_STOP, false); 148 reload_.ChangeMode(ReloadButton::MODE_STOP, false);
150 set_mouse_hovered(true); 149 set_mouse_hovered(true);
151 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); 150 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false);
152 151
153 // Now fire the stop-to-reload timer. This should reset the button. 152 // Now fire the stop-to-reload timer. This should reset the button.
154 loop_.RunUntilIdle(); 153 base::MessageLoop::current()->RunUntilIdle();
155 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, 154 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
156 false); 155 false);
157 } 156 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/reload_button.cc ('k') | chrome/browser/ui/views/toolbar/toolbar_action_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698