OLD | NEW |
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/path_service.h" | 5 #include "base/path_service.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
10 #include "chrome/browser/chrome_content_browser_client.h" | 10 #include "chrome/browser/chrome_content_browser_client.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 217 |
218 private: | 218 private: |
219 bool requested_; | 219 bool requested_; |
220 bool checked_; | 220 bool checked_; |
221 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_; | 221 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_; |
222 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_; | 222 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_; |
223 | 223 |
224 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate); | 224 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate); |
225 }; | 225 }; |
226 | 226 |
| 227 class MockWebViewGuestDelegate : public extensions::WebViewGuestDelegate { |
| 228 public: |
| 229 explicit MockWebViewGuestDelegate(extensions::WebViewGuest* web_view_guest) |
| 230 : web_view_guest_(web_view_guest), clear_cache_called_(false) {} |
| 231 ~MockWebViewGuestDelegate() override {} |
| 232 |
| 233 // WebViewGuestDelegate implementation. |
| 234 void ClearCache(base::Time remove_since, |
| 235 const base::Closure& callback) override { |
| 236 clear_cache_called_ = true; |
| 237 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 238 } |
| 239 bool HandleContextMenu(const content::ContextMenuParams& params) override { |
| 240 return false; |
| 241 } |
| 242 void OnAttachWebViewHelpers(content::WebContents* contents) override {} |
| 243 void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) override {} |
| 244 void OnDidInitialize() override {} |
| 245 void OnDocumentLoadedInFrame( |
| 246 content::RenderFrameHost* render_frame_host) override {} |
| 247 void OnGuestDestroyed() override {} |
| 248 void OnShowContextMenu( |
| 249 int request_id, |
| 250 const WebViewGuestDelegate::MenuItemVector* items) override {} |
| 251 |
| 252 bool clear_cache_called() { return clear_cache_called_; } |
| 253 |
| 254 private: |
| 255 extensions::WebViewGuest* web_view_guest_; |
| 256 bool clear_cache_called_; |
| 257 |
| 258 DISALLOW_COPY_AND_ASSIGN(MockWebViewGuestDelegate); |
| 259 }; |
| 260 |
227 // This class intercepts download request from the guest. | 261 // This class intercepts download request from the guest. |
228 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { | 262 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { |
229 public: | 263 public: |
230 explicit MockDownloadWebContentsDelegate( | 264 explicit MockDownloadWebContentsDelegate( |
231 content::WebContentsDelegate* orig_delegate) | 265 content::WebContentsDelegate* orig_delegate) |
232 : orig_delegate_(orig_delegate), | 266 : orig_delegate_(orig_delegate), |
233 waiting_for_decision_(false), | 267 waiting_for_decision_(false), |
234 expect_allow_(false), | 268 expect_allow_(false), |
235 decision_made_(false), | 269 decision_made_(false), |
236 last_download_allowed_(false) {} | 270 last_download_allowed_(false) {} |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 | 693 |
660 ExtensionTestMessageListener test_run_listener("PASSED", false); | 694 ExtensionTestMessageListener test_run_listener("PASSED", false); |
661 test_run_listener.set_failure_message("FAILED"); | 695 test_run_listener.set_failure_message("FAILED"); |
662 EXPECT_TRUE( | 696 EXPECT_TRUE( |
663 content::ExecuteScript( | 697 content::ExecuteScript( |
664 embedder_web_contents, | 698 embedder_web_contents, |
665 base::StringPrintf("startDenyTest('%s')", test_name.c_str()))); | 699 base::StringPrintf("startDenyTest('%s')", test_name.c_str()))); |
666 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied()); | 700 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied()); |
667 } | 701 } |
668 | 702 |
| 703 // Loads an app with a <webview> in it, returns once a guest is created. |
669 void LoadAppWithGuest(const std::string& app_path) { | 704 void LoadAppWithGuest(const std::string& app_path) { |
670 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED", | 705 ExtensionTestMessageListener launched_listener("WebViewTest.LAUNCHED", |
671 false); | 706 false); |
672 launched_listener.set_failure_message("WebViewTest.FAILURE"); | 707 launched_listener.set_failure_message("WebViewTest.FAILURE"); |
673 LoadAndLaunchPlatformApp(app_path.c_str(), &launched_listener); | 708 LoadAndLaunchPlatformApp(app_path.c_str(), &launched_listener); |
674 | 709 |
675 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated(); | 710 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated(); |
676 } | 711 } |
677 | 712 |
678 void SendMessageToEmbedder(const std::string& message) { | 713 void SendMessageToEmbedder(const std::string& message) { |
(...skipping 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2250 if (base::win::GetVersion() <= base::win::VERSION_XP) | 2285 if (base::win::GetVersion() <= base::win::VERSION_XP) |
2251 return; | 2286 return; |
2252 #endif | 2287 #endif |
2253 | 2288 |
2254 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. | 2289 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. |
2255 ASSERT_TRUE(RunPlatformAppTestWithArg( | 2290 ASSERT_TRUE(RunPlatformAppTestWithArg( |
2256 "platform_apps/web_view/common", "cleardata")) | 2291 "platform_apps/web_view/common", "cleardata")) |
2257 << message_; | 2292 << message_; |
2258 } | 2293 } |
2259 | 2294 |
| 2295 IN_PROC_BROWSER_TEST_F(WebViewTest, ClearDataCache) { |
| 2296 LoadAppWithGuest("web_view/clear_data_cache"); |
| 2297 content::WebContents* guest_web_contents = GetGuestWebContents(); |
| 2298 auto guest = extensions::WebViewGuest::FromWebContents(guest_web_contents); |
| 2299 ASSERT_TRUE(guest); |
| 2300 scoped_ptr<extensions::WebViewGuestDelegate> mock_web_view_guest_delegate( |
| 2301 new MockWebViewGuestDelegate(guest)); |
| 2302 scoped_ptr<extensions::WebViewGuestDelegate> orig_web_view_guest_delegate = |
| 2303 guest->SetDelegateForTesting(mock_web_view_guest_delegate.Pass()); |
| 2304 |
| 2305 ASSERT_TRUE(GetEmbedderWebContents()); |
| 2306 ExtensionTestMessageListener clear_data_done_listener( |
| 2307 "WebViewTest.CLEAR_DATA_DONE", false); |
| 2308 EXPECT_TRUE(content::ExecuteScript( |
| 2309 GetEmbedderWebContents(), base::StringPrintf("testClearDataCache()"))); |
| 2310 EXPECT_TRUE(clear_data_done_listener.WaitUntilSatisfied()); |
| 2311 |
| 2312 // Reset delegate back to original once we're done mocking. |
| 2313 mock_web_view_guest_delegate = |
| 2314 guest->SetDelegateForTesting(orig_web_view_guest_delegate.Pass()); |
| 2315 } |
| 2316 |
2260 // This test is disabled on Win due to being flaky. http://crbug.com/294592 | 2317 // This test is disabled on Win due to being flaky. http://crbug.com/294592 |
2261 #if defined(OS_WIN) | 2318 #if defined(OS_WIN) |
2262 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage | 2319 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage |
2263 #else | 2320 #else |
2264 #define MAYBE_ConsoleMessage ConsoleMessage | 2321 #define MAYBE_ConsoleMessage ConsoleMessage |
2265 #endif | 2322 #endif |
2266 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) { | 2323 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) { |
2267 ASSERT_TRUE(RunPlatformAppTestWithArg( | 2324 ASSERT_TRUE(RunPlatformAppTestWithArg( |
2268 "platform_apps/web_view/common", "console_messages")) | 2325 "platform_apps/web_view/common", "console_messages")) |
2269 << message_; | 2326 << message_; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2594 // http://crbug.com/403325 | 2651 // http://crbug.com/403325 |
2595 #define MAYBE_WebViewInBackgroundPage \ | 2652 #define MAYBE_WebViewInBackgroundPage \ |
2596 DISABLED_WebViewInBackgroundPage | 2653 DISABLED_WebViewInBackgroundPage |
2597 #else | 2654 #else |
2598 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage | 2655 #define MAYBE_WebViewInBackgroundPage WebViewInBackgroundPage |
2599 #endif | 2656 #endif |
2600 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { | 2657 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_WebViewInBackgroundPage) { |
2601 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) | 2658 ASSERT_TRUE(RunExtensionTest("platform_apps/web_view/background")) |
2602 << message_; | 2659 << message_; |
2603 } | 2660 } |
OLD | NEW |