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

Side by Side Diff: chrome/browser/ui/exclusive_access/flash_fullscreen_interactive_browsertest.cc

Issue 1412963003: Plugin Power Saver: Implement pixel tests for plugin placeholders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl formatted Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/interactive_test_utils.h" 13 #include "chrome/test/base/interactive_test_utils.h"
14 #include "chrome/test/ppapi/ppapi_test.h" 14 #include "chrome/test/ppapi/ppapi_test.h"
15 #include "content/public/browser/render_widget_host.h" 15 #include "content/public/browser/render_widget_host.h"
16 #include "content/public/browser/render_widget_host_view.h" 16 #include "content/public/browser/render_widget_host_view.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
19 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
20 20
21 namespace { 21 namespace {
22 22
23 #if defined(OS_MACOSX) 23 #if defined(OS_MACOSX)
24 const bool kIsMacUI = true; 24 const bool kIsMacUI = true;
25 #else 25 #else
26 const bool kIsMacUI = false; 26 const bool kIsMacUI = false;
27 #endif 27 #endif
28 28
29 // Runs the current MessageLoop until |condition| is true or timeout.
30 bool RunLoopUntil(const base::Callback<bool()>& condition) {
31 const base::TimeTicks start_time = base::TimeTicks::Now();
32 while (!condition.Run()) {
33 const base::TimeTicks current_time = base::TimeTicks::Now();
34 if (current_time - start_time > base::TimeDelta::FromSeconds(10)) {
35 ADD_FAILURE() << "Condition not met within ten seconds.";
36 return false;
37 }
38
39 base::MessageLoop::current()->task_runner()->PostDelayedTask(
40 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
41 base::TimeDelta::FromMilliseconds(20));
42 content::RunMessageLoop();
43 }
44 return true;
45 }
46
47 } // namespace 29 } // namespace
48 30
49 // A BrowserTest that opens a test page that launches a simulated fullscreen 31 // A BrowserTest that opens a test page that launches a simulated fullscreen
50 // Flash plugin. The plugin responds to mouse clicks and key presses by 32 // Flash plugin. The plugin responds to mouse clicks and key presses by
51 // changing color. Once launched, the browser UI can be tested to confirm the 33 // changing color. Once launched, the browser UI can be tested to confirm the
52 // desired interactive behaviors. 34 // desired interactive behaviors.
53 class FlashFullscreenInteractiveBrowserTest : public OutOfProcessPPAPITest { 35 class FlashFullscreenInteractiveBrowserTest : public OutOfProcessPPAPITest {
54 public: 36 public:
55 FlashFullscreenInteractiveBrowserTest() {} 37 FlashFullscreenInteractiveBrowserTest() {}
56 ~FlashFullscreenInteractiveBrowserTest() override {} 38 ~FlashFullscreenInteractiveBrowserTest() override {}
(...skipping 24 matching lines...) Expand all
81 63
82 EXPECT_TRUE(ObserveTabIsInFullscreen(true)); 64 EXPECT_TRUE(ObserveTabIsInFullscreen(true));
83 65
84 return !::testing::Test::HasFailure(); 66 return !::testing::Test::HasFailure();
85 } 67 }
86 68
87 void UseAcceleratorToOpenNewTab() { 69 void UseAcceleratorToOpenNewTab() {
88 content::WebContents* const old_tab_contents = GetActiveWebContents(); 70 content::WebContents* const old_tab_contents = GetActiveWebContents();
89 EXPECT_TRUE(ui_test_utils::SendKeyPressSync( 71 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(
90 browser(), ui::VKEY_T, !kIsMacUI, false, false, kIsMacUI)); 72 browser(), ui::VKEY_T, !kIsMacUI, false, false, kIsMacUI));
91 EXPECT_TRUE(RunLoopUntil(base::Bind( 73 EXPECT_TRUE(ui_test_utils::RunLoopUntil(base::Bind(
92 &FlashFullscreenInteractiveBrowserTest::IsObservingActiveWebContents, 74 &FlashFullscreenInteractiveBrowserTest::IsObservingActiveWebContents,
93 base::Unretained(this), 75 base::Unretained(this), old_tab_contents, false)));
94 old_tab_contents,
95 false)));
96 } 76 }
97 77
98 void UseAcceleratorToSwitchToTab(int tab_index) { 78 void UseAcceleratorToSwitchToTab(int tab_index) {
99 content::WebContents* const old_tab_contents = GetActiveWebContents(); 79 content::WebContents* const old_tab_contents = GetActiveWebContents();
100 const ui::KeyboardCode key_code = 80 const ui::KeyboardCode key_code =
101 static_cast<ui::KeyboardCode>(ui::VKEY_1 + tab_index); 81 static_cast<ui::KeyboardCode>(ui::VKEY_1 + tab_index);
102 EXPECT_TRUE(ui_test_utils::SendKeyPressSync( 82 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(
103 browser(), key_code, !kIsMacUI, false, false, kIsMacUI)); 83 browser(), key_code, !kIsMacUI, false, false, kIsMacUI));
104 EXPECT_TRUE(RunLoopUntil(base::Bind( 84 EXPECT_TRUE(ui_test_utils::RunLoopUntil(base::Bind(
105 &FlashFullscreenInteractiveBrowserTest::IsObservingActiveWebContents, 85 &FlashFullscreenInteractiveBrowserTest::IsObservingActiveWebContents,
106 base::Unretained(this), 86 base::Unretained(this), old_tab_contents, false)));
107 old_tab_contents,
108 false)));
109 } 87 }
110 88
111 void PressEscape() { 89 void PressEscape() {
112 EXPECT_TRUE(ui_test_utils::SendKeyPressSync( 90 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(
113 browser(), ui::VKEY_ESCAPE, false, false, false, false)); 91 browser(), ui::VKEY_ESCAPE, false, false, false, false));
114 } 92 }
115 93
116 void PressSpacebar() { 94 void PressSpacebar() {
117 EXPECT_TRUE(ui_test_utils::SendKeyPressSync( 95 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(
118 browser(), ui::VKEY_SPACE, false, false, false, false)); 96 browser(), ui::VKEY_SPACE, false, false, false, false));
119 } 97 }
120 98
121 void SpamSpacebar() { 99 void SpamSpacebar() {
122 for (int i = 0; i < 11; ++i) 100 for (int i = 0; i < 11; ++i)
123 PressSpacebar(); 101 PressSpacebar();
124 } 102 }
125 103
126 void ClickOnTabContainer() { 104 void ClickOnTabContainer() {
127 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); 105 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
128 } 106 }
129 107
130 void ClickOnOmnibox() { 108 void ClickOnOmnibox() {
131 ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX); 109 ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX);
132 } 110 }
133 111
134 bool ObserveTabIsInFullscreen(bool expected_in_fullscreen) const { 112 bool ObserveTabIsInFullscreen(bool expected_in_fullscreen) const {
135 if (!RunLoopUntil(base::Bind( 113 if (!ui_test_utils::RunLoopUntil(base::Bind(
136 &FlashFullscreenInteractiveBrowserTest::IsObservingTabInFullscreen, 114 &FlashFullscreenInteractiveBrowserTest::IsObservingTabInFullscreen,
137 base::Unretained(this), 115 base::Unretained(this), GetActiveWebContents(),
138 GetActiveWebContents(),
139 expected_in_fullscreen))) 116 expected_in_fullscreen)))
140 return false; 117 return false;
141 118
142 if (expected_in_fullscreen) { 119 if (expected_in_fullscreen) {
143 if (!GetActiveWebContents()->GetFullscreenRenderWidgetHostView()) { 120 if (!GetActiveWebContents()->GetFullscreenRenderWidgetHostView()) {
144 ADD_FAILURE() 121 ADD_FAILURE()
145 << "WebContents should have a fullscreen RenderWidgetHostView."; 122 << "WebContents should have a fullscreen RenderWidgetHostView.";
146 return false; 123 return false;
147 } 124 }
148 EXPECT_EQ(GetActiveWebContents()->GetCapturerCount() > 0, 125 EXPECT_EQ(GetActiveWebContents()->GetCapturerCount() > 0,
149 !browser() 126 !browser()
150 ->exclusive_access_manager() 127 ->exclusive_access_manager()
151 ->fullscreen_controller() 128 ->fullscreen_controller()
152 ->IsWindowFullscreenForTabOrPending()); 129 ->IsWindowFullscreenForTabOrPending());
153 } 130 }
154 131
155 return true; 132 return true;
156 } 133 }
157 134
158 bool ObserveFlashHasFocus(content::WebContents* contents, 135 bool ObserveFlashHasFocus(content::WebContents* contents,
159 bool expected_to_have_focus) const { 136 bool expected_to_have_focus) const {
160 if (!RunLoopUntil(base::Bind( 137 if (!ui_test_utils::RunLoopUntil(base::Bind(
161 &FlashFullscreenInteractiveBrowserTest::IsObservingFlashHasFocus, 138 &FlashFullscreenInteractiveBrowserTest::IsObservingFlashHasFocus,
162 base::Unretained(this), 139 base::Unretained(this), contents, expected_to_have_focus)))
163 contents,
164 expected_to_have_focus)))
165 return false; 140 return false;
166 141
167 if (expected_to_have_focus) { 142 if (expected_to_have_focus) {
168 content::RenderWidgetHostView* const web_page_view = 143 content::RenderWidgetHostView* const web_page_view =
169 contents->GetRenderWidgetHostView(); 144 contents->GetRenderWidgetHostView();
170 EXPECT_FALSE(web_page_view && web_page_view->HasFocus()) 145 EXPECT_FALSE(web_page_view && web_page_view->HasFocus())
171 << "Both RenderWidgetHostViews cannot have focus at the same time."; 146 << "Both RenderWidgetHostViews cannot have focus at the same time.";
172 147
173 if (contents == GetActiveWebContents()) 148 if (contents == GetActiveWebContents())
174 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 149 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
175 VIEW_ID_TAB_CONTAINER)); 150 VIEW_ID_TAB_CONTAINER));
176 } 151 }
177 152
178 return true; 153 return true;
179 } 154 }
180 155
181 bool ObserveFlashFillColor(SkColor expected_color) const { 156 bool ObserveFlashFillColor(SkColor expected_color) const {
182 return RunLoopUntil(base::Bind( 157 return ui_test_utils::RunLoopUntil(base::Bind(
183 &FlashFullscreenInteractiveBrowserTest::IsObservingFlashFillColor, 158 &FlashFullscreenInteractiveBrowserTest::IsObservingFlashFillColor,
184 base::Unretained(this), 159 base::Unretained(this), expected_color));
185 expected_color));
186 } 160 }
187 161
188 private: 162 private:
189 bool IsObservingTabInFullscreen(content::WebContents* contents, 163 bool IsObservingTabInFullscreen(content::WebContents* contents,
190 bool expected_in_fullscreen) const { 164 bool expected_in_fullscreen) const {
191 return expected_in_fullscreen == 165 return expected_in_fullscreen ==
192 browser() 166 browser()
193 ->exclusive_access_manager() 167 ->exclusive_access_manager()
194 ->fullscreen_controller() 168 ->fullscreen_controller()
195 ->IsFullscreenForTabOrPending(contents); 169 ->IsFullscreenForTabOrPending(contents);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 ASSERT_TRUE(ObserveFlashFillColor(SK_ColorRED)); 317 ASSERT_TRUE(ObserveFlashFillColor(SK_ColorRED));
344 PressSpacebar(); 318 PressSpacebar();
345 ASSERT_TRUE(ObserveFlashFillColor(SK_ColorBLUE)); 319 ASSERT_TRUE(ObserveFlashFillColor(SK_ColorBLUE));
346 320
347 // Test that the Escape key is handled as an exit fullscreen command while the 321 // Test that the Escape key is handled as an exit fullscreen command while the
348 // Flash widget has the focus. 322 // Flash widget has the focus.
349 EXPECT_TRUE(ObserveFlashHasFocus(first_tab_contents, true)); 323 EXPECT_TRUE(ObserveFlashHasFocus(first_tab_contents, true));
350 PressEscape(); 324 PressEscape();
351 EXPECT_TRUE(ObserveTabIsInFullscreen(false)); 325 EXPECT_TRUE(ObserveTabIsInFullscreen(false));
352 } 326 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698