OLD | NEW |
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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/browser/frame_host/cross_site_transferring_request.h" | 7 #include "content/browser/frame_host/cross_site_transferring_request.h" |
8 #include "content/browser/frame_host/interstitial_page_impl.h" | 8 #include "content/browser/frame_host/interstitial_page_impl.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/media/audio_stream_monitor.h" | 10 #include "content/browser/media/audio_stream_monitor.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
38 | 38 |
39 namespace content { | 39 namespace content { |
40 namespace { | 40 namespace { |
41 | 41 |
42 const char kTestWebUIUrl[] = "chrome://blah"; | 42 const char kTestWebUIUrl[] = "chrome://blah"; |
43 | 43 |
44 class WebContentsImplTestWebUIControllerFactory | 44 class WebContentsImplTestWebUIControllerFactory |
45 : public WebUIControllerFactory { | 45 : public WebUIControllerFactory { |
46 public: | 46 public: |
47 virtual WebUIController* CreateWebUIControllerForURL( | 47 WebUIController* CreateWebUIControllerForURL(WebUI* web_ui, |
48 WebUI* web_ui, const GURL& url) const override { | 48 const GURL& url) const override { |
49 if (!UseWebUI(url)) | 49 if (!UseWebUI(url)) |
50 return NULL; | 50 return NULL; |
51 return new WebUIController(web_ui); | 51 return new WebUIController(web_ui); |
52 } | 52 } |
53 | 53 |
54 virtual WebUI::TypeID GetWebUIType(BrowserContext* browser_context, | 54 WebUI::TypeID GetWebUIType(BrowserContext* browser_context, |
55 const GURL& url) const override { | 55 const GURL& url) const override { |
56 return WebUI::kNoWebUI; | 56 return WebUI::kNoWebUI; |
57 } | 57 } |
58 | 58 |
59 virtual bool UseWebUIForURL(BrowserContext* browser_context, | 59 bool UseWebUIForURL(BrowserContext* browser_context, |
| 60 const GURL& url) const override { |
| 61 return UseWebUI(url); |
| 62 } |
| 63 |
| 64 bool UseWebUIBindingsForURL(BrowserContext* browser_context, |
60 const GURL& url) const override { | 65 const GURL& url) const override { |
61 return UseWebUI(url); | 66 return UseWebUI(url); |
62 } | 67 } |
63 | 68 |
64 virtual bool UseWebUIBindingsForURL(BrowserContext* browser_context, | |
65 const GURL& url) const override { | |
66 return UseWebUI(url); | |
67 } | |
68 | |
69 private: | 69 private: |
70 bool UseWebUI(const GURL& url) const { | 70 bool UseWebUI(const GURL& url) const { |
71 return url == GURL(kTestWebUIUrl); | 71 return url == GURL(kTestWebUIUrl); |
72 } | 72 } |
73 }; | 73 }; |
74 | 74 |
75 class TestInterstitialPage; | 75 class TestInterstitialPage; |
76 | 76 |
77 class TestInterstitialPageDelegate : public InterstitialPageDelegate { | 77 class TestInterstitialPageDelegate : public InterstitialPageDelegate { |
78 public: | 78 public: |
79 explicit TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) | 79 explicit TestInterstitialPageDelegate(TestInterstitialPage* interstitial_page) |
80 : interstitial_page_(interstitial_page) {} | 80 : interstitial_page_(interstitial_page) {} |
81 virtual void CommandReceived(const std::string& command) override; | 81 void CommandReceived(const std::string& command) override; |
82 virtual std::string GetHTMLContents() override { return std::string(); } | 82 std::string GetHTMLContents() override { return std::string(); } |
83 virtual void OnDontProceed() override; | 83 void OnDontProceed() override; |
84 virtual void OnProceed() override; | 84 void OnProceed() override; |
| 85 |
85 private: | 86 private: |
86 TestInterstitialPage* interstitial_page_; | 87 TestInterstitialPage* interstitial_page_; |
87 }; | 88 }; |
88 | 89 |
89 class TestInterstitialPage : public InterstitialPageImpl { | 90 class TestInterstitialPage : public InterstitialPageImpl { |
90 public: | 91 public: |
91 enum InterstitialState { | 92 enum InterstitialState { |
92 INVALID = 0, // Hasn't yet been initialized. | 93 INVALID = 0, // Hasn't yet been initialized. |
93 UNDECIDED, // Initialized, but no decision taken yet. | 94 UNDECIDED, // Initialized, but no decision taken yet. |
94 OKED, // Proceed was called. | 95 OKED, // Proceed was called. |
(...skipping 28 matching lines...) Expand all Loading... |
123 static_cast<RenderWidgetHostDelegate*>(contents), | 124 static_cast<RenderWidgetHostDelegate*>(contents), |
124 new_navigation, url, new TestInterstitialPageDelegate(this)), | 125 new_navigation, url, new TestInterstitialPageDelegate(this)), |
125 state_(state), | 126 state_(state), |
126 deleted_(deleted), | 127 deleted_(deleted), |
127 command_received_count_(0), | 128 command_received_count_(0), |
128 delegate_(NULL) { | 129 delegate_(NULL) { |
129 *state_ = UNDECIDED; | 130 *state_ = UNDECIDED; |
130 *deleted_ = false; | 131 *deleted_ = false; |
131 } | 132 } |
132 | 133 |
133 virtual ~TestInterstitialPage() { | 134 ~TestInterstitialPage() override { |
134 if (deleted_) | 135 if (deleted_) |
135 *deleted_ = true; | 136 *deleted_ = true; |
136 if (delegate_) | 137 if (delegate_) |
137 delegate_->TestInterstitialPageDeleted(this); | 138 delegate_->TestInterstitialPageDeleted(this); |
138 } | 139 } |
139 | 140 |
140 void OnDontProceed() { | 141 void OnDontProceed() { |
141 if (state_) | 142 if (state_) |
142 *state_ = CANCELED; | 143 *state_ = CANCELED; |
143 } | 144 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 180 |
180 void CommandReceived() { | 181 void CommandReceived() { |
181 command_received_count_++; | 182 command_received_count_++; |
182 } | 183 } |
183 | 184 |
184 void set_delegate(Delegate* delegate) { | 185 void set_delegate(Delegate* delegate) { |
185 delegate_ = delegate; | 186 delegate_ = delegate; |
186 } | 187 } |
187 | 188 |
188 protected: | 189 protected: |
189 virtual WebContentsView* CreateWebContentsView() override { | 190 WebContentsView* CreateWebContentsView() override { return NULL; } |
190 return NULL; | |
191 } | |
192 | 191 |
193 private: | 192 private: |
194 InterstitialState* state_; | 193 InterstitialState* state_; |
195 bool* deleted_; | 194 bool* deleted_; |
196 int command_received_count_; | 195 int command_received_count_; |
197 Delegate* delegate_; | 196 Delegate* delegate_; |
198 }; | 197 }; |
199 | 198 |
200 void TestInterstitialPageDelegate::CommandReceived(const std::string& command) { | 199 void TestInterstitialPageDelegate::CommandReceived(const std::string& command) { |
201 interstitial_page_->CommandReceived(); | 200 interstitial_page_->CommandReceived(); |
202 } | 201 } |
203 | 202 |
204 void TestInterstitialPageDelegate::OnDontProceed() { | 203 void TestInterstitialPageDelegate::OnDontProceed() { |
205 interstitial_page_->OnDontProceed(); | 204 interstitial_page_->OnDontProceed(); |
206 } | 205 } |
207 | 206 |
208 void TestInterstitialPageDelegate::OnProceed() { | 207 void TestInterstitialPageDelegate::OnProceed() { |
209 interstitial_page_->OnProceed(); | 208 interstitial_page_->OnProceed(); |
210 } | 209 } |
211 | 210 |
212 class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate { | 211 class TestInterstitialPageStateGuard : public TestInterstitialPage::Delegate { |
213 public: | 212 public: |
214 explicit TestInterstitialPageStateGuard( | 213 explicit TestInterstitialPageStateGuard( |
215 TestInterstitialPage* interstitial_page) | 214 TestInterstitialPage* interstitial_page) |
216 : interstitial_page_(interstitial_page) { | 215 : interstitial_page_(interstitial_page) { |
217 DCHECK(interstitial_page_); | 216 DCHECK(interstitial_page_); |
218 interstitial_page_->set_delegate(this); | 217 interstitial_page_->set_delegate(this); |
219 } | 218 } |
220 virtual ~TestInterstitialPageStateGuard() { | 219 ~TestInterstitialPageStateGuard() override { |
221 if (interstitial_page_) | 220 if (interstitial_page_) |
222 interstitial_page_->ClearStates(); | 221 interstitial_page_->ClearStates(); |
223 } | 222 } |
224 | 223 |
225 virtual void TestInterstitialPageDeleted( | 224 void TestInterstitialPageDeleted( |
226 TestInterstitialPage* interstitial) override { | 225 TestInterstitialPage* interstitial) override { |
227 DCHECK(interstitial_page_ == interstitial); | 226 DCHECK(interstitial_page_ == interstitial); |
228 interstitial_page_ = NULL; | 227 interstitial_page_ = NULL; |
229 } | 228 } |
230 | 229 |
231 private: | 230 private: |
232 TestInterstitialPage* interstitial_page_; | 231 TestInterstitialPage* interstitial_page_; |
233 }; | 232 }; |
234 | 233 |
235 class WebContentsImplTestBrowserClient : public TestContentBrowserClient { | 234 class WebContentsImplTestBrowserClient : public TestContentBrowserClient { |
236 public: | 235 public: |
237 WebContentsImplTestBrowserClient() | 236 WebContentsImplTestBrowserClient() |
238 : assign_site_for_url_(false) {} | 237 : assign_site_for_url_(false) {} |
239 | 238 |
240 virtual ~WebContentsImplTestBrowserClient() {} | 239 ~WebContentsImplTestBrowserClient() override {} |
241 | 240 |
242 virtual bool ShouldAssignSiteForURL(const GURL& url) override { | 241 bool ShouldAssignSiteForURL(const GURL& url) override { |
243 return assign_site_for_url_; | 242 return assign_site_for_url_; |
244 } | 243 } |
245 | 244 |
246 void set_assign_site_for_url(bool assign) { | 245 void set_assign_site_for_url(bool assign) { |
247 assign_site_for_url_ = assign; | 246 assign_site_for_url_ = assign; |
248 } | 247 } |
249 | 248 |
250 private: | 249 private: |
251 bool assign_site_for_url_; | 250 bool assign_site_for_url_; |
252 }; | 251 }; |
(...skipping 12 matching lines...) Expand all Loading... |
265 | 264 |
266 private: | 265 private: |
267 WebContentsImplTestWebUIControllerFactory factory_; | 266 WebContentsImplTestWebUIControllerFactory factory_; |
268 }; | 267 }; |
269 | 268 |
270 class TestWebContentsObserver : public WebContentsObserver { | 269 class TestWebContentsObserver : public WebContentsObserver { |
271 public: | 270 public: |
272 explicit TestWebContentsObserver(WebContents* contents) | 271 explicit TestWebContentsObserver(WebContents* contents) |
273 : WebContentsObserver(contents) { | 272 : WebContentsObserver(contents) { |
274 } | 273 } |
275 virtual ~TestWebContentsObserver() {} | 274 ~TestWebContentsObserver() override {} |
276 | 275 |
277 virtual void DidFinishLoad(RenderFrameHost* render_frame_host, | 276 void DidFinishLoad(RenderFrameHost* render_frame_host, |
278 const GURL& validated_url) override { | 277 const GURL& validated_url) override { |
279 last_url_ = validated_url; | 278 last_url_ = validated_url; |
280 } | 279 } |
281 virtual void DidFailLoad(RenderFrameHost* render_frame_host, | 280 void DidFailLoad(RenderFrameHost* render_frame_host, |
282 const GURL& validated_url, | 281 const GURL& validated_url, |
283 int error_code, | 282 int error_code, |
284 const base::string16& error_description) override { | 283 const base::string16& error_description) override { |
285 last_url_ = validated_url; | 284 last_url_ = validated_url; |
286 } | 285 } |
287 | 286 |
288 const GURL& last_url() const { return last_url_; } | 287 const GURL& last_url() const { return last_url_; } |
289 | 288 |
290 private: | 289 private: |
291 GURL last_url_; | 290 GURL last_url_; |
292 | 291 |
293 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); | 292 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); |
294 }; | 293 }; |
295 | 294 |
296 // Pretends to be a normal browser that receives toggles and transitions to/from | 295 // Pretends to be a normal browser that receives toggles and transitions to/from |
297 // a fullscreened state. | 296 // a fullscreened state. |
298 class FakeFullscreenDelegate : public WebContentsDelegate { | 297 class FakeFullscreenDelegate : public WebContentsDelegate { |
299 public: | 298 public: |
300 FakeFullscreenDelegate() : fullscreened_contents_(NULL) {} | 299 FakeFullscreenDelegate() : fullscreened_contents_(NULL) {} |
301 virtual ~FakeFullscreenDelegate() {} | 300 ~FakeFullscreenDelegate() override {} |
302 | 301 |
303 virtual void ToggleFullscreenModeForTab(WebContents* web_contents, | 302 void ToggleFullscreenModeForTab(WebContents* web_contents, |
304 bool enter_fullscreen) override { | 303 bool enter_fullscreen) override { |
305 fullscreened_contents_ = enter_fullscreen ? web_contents : NULL; | 304 fullscreened_contents_ = enter_fullscreen ? web_contents : NULL; |
306 } | 305 } |
307 | 306 |
308 virtual bool IsFullscreenForTabOrPending(const WebContents* web_contents) | 307 bool IsFullscreenForTabOrPending( |
309 const override { | 308 const WebContents* web_contents) const override { |
310 return fullscreened_contents_ && web_contents == fullscreened_contents_; | 309 return fullscreened_contents_ && web_contents == fullscreened_contents_; |
311 } | 310 } |
312 | 311 |
313 private: | 312 private: |
314 WebContents* fullscreened_contents_; | 313 WebContents* fullscreened_contents_; |
315 | 314 |
316 DISALLOW_COPY_AND_ASSIGN(FakeFullscreenDelegate); | 315 DISALLOW_COPY_AND_ASSIGN(FakeFullscreenDelegate); |
317 }; | 316 }; |
318 | 317 |
319 class FakeValidationMessageDelegate : public WebContentsDelegate { | 318 class FakeValidationMessageDelegate : public WebContentsDelegate { |
320 public: | 319 public: |
321 FakeValidationMessageDelegate() | 320 FakeValidationMessageDelegate() |
322 : hide_validation_message_was_called_(false) {} | 321 : hide_validation_message_was_called_(false) {} |
323 virtual ~FakeValidationMessageDelegate() {} | 322 ~FakeValidationMessageDelegate() override {} |
324 | 323 |
325 virtual void HideValidationMessage(WebContents* web_contents) override { | 324 void HideValidationMessage(WebContents* web_contents) override { |
326 hide_validation_message_was_called_ = true; | 325 hide_validation_message_was_called_ = true; |
327 } | 326 } |
328 | 327 |
329 bool hide_validation_message_was_called() const { | 328 bool hide_validation_message_was_called() const { |
330 return hide_validation_message_was_called_; | 329 return hide_validation_message_was_called_; |
331 } | 330 } |
332 | 331 |
333 private: | 332 private: |
334 bool hide_validation_message_was_called_; | 333 bool hide_validation_message_was_called_; |
335 | 334 |
(...skipping 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2446 int count = contents_zoom_changed_call_count_; | 2445 int count = contents_zoom_changed_call_count_; |
2447 contents_zoom_changed_call_count_ = 0; | 2446 contents_zoom_changed_call_count_ = 0; |
2448 return count; | 2447 return count; |
2449 } | 2448 } |
2450 | 2449 |
2451 bool last_zoom_in() const { | 2450 bool last_zoom_in() const { |
2452 return last_zoom_in_; | 2451 return last_zoom_in_; |
2453 } | 2452 } |
2454 | 2453 |
2455 // WebContentsDelegate: | 2454 // WebContentsDelegate: |
2456 virtual void ContentsZoomChange(bool zoom_in) override { | 2455 void ContentsZoomChange(bool zoom_in) override { |
2457 contents_zoom_changed_call_count_++; | 2456 contents_zoom_changed_call_count_++; |
2458 last_zoom_in_ = zoom_in; | 2457 last_zoom_in_ = zoom_in; |
2459 } | 2458 } |
2460 | 2459 |
2461 private: | 2460 private: |
2462 int contents_zoom_changed_call_count_; | 2461 int contents_zoom_changed_call_count_; |
2463 bool last_zoom_in_; | 2462 bool last_zoom_in_; |
2464 | 2463 |
2465 DISALLOW_COPY_AND_ASSIGN(ContentsZoomChangedDelegate); | 2464 DISALLOW_COPY_AND_ASSIGN(ContentsZoomChangedDelegate); |
2466 }; | 2465 }; |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2789 | 2788 |
2790 // Destroy the remote player. No power save blockers should remain. | 2789 // Destroy the remote player. No power save blockers should remain. |
2791 rfh->OnMessageReceived( | 2790 rfh->OnMessageReceived( |
2792 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); | 2791 FrameHostMsg_MediaPausedNotification(0, kPlayerRemoteId)); |
2793 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); | 2792 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); |
2794 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); | 2793 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); |
2795 } | 2794 } |
2796 #endif | 2795 #endif |
2797 | 2796 |
2798 } // namespace content | 2797 } // namespace content |
OLD | NEW |