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

Side by Side Diff: chrome/browser/apps/guest_view/web_view_browsertest.cc

Issue 1056793002: Move clear cache code from chrome/ (ChromeWVGDelegate) to extensions/ (WVGuest) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-spbdr
Patch Set: fix test on windows Created 5 years, 8 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 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/process/process.h" 6 #include "base/process/process.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/apps/app_browsertest_util.h" 10 #include "chrome/browser/apps/app_browsertest_util.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 using task_manager::browsertest_util::MatchApp; 82 using task_manager::browsertest_util::MatchApp;
83 using task_manager::browsertest_util::MatchBackground; 83 using task_manager::browsertest_util::MatchBackground;
84 using task_manager::browsertest_util::MatchWebView; 84 using task_manager::browsertest_util::MatchWebView;
85 using task_manager::browsertest_util::WaitForTaskManagerRows; 85 using task_manager::browsertest_util::WaitForTaskManagerRows;
86 using ui::MenuModel; 86 using ui::MenuModel;
87 87
88 namespace { 88 namespace {
89 const char kEmptyResponsePath[] = "/close-socket"; 89 const char kEmptyResponsePath[] = "/close-socket";
90 const char kRedirectResponsePath[] = "/server-redirect"; 90 const char kRedirectResponsePath[] = "/server-redirect";
91 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent"; 91 const char kUserAgentRedirectResponsePath[] = "/detect-user-agent";
92 const char kCacheResponsePath[] = "/cache-control-response";
92 const char kRedirectResponseFullPath[] = 93 const char kRedirectResponseFullPath[] =
93 "/extensions/platform_apps/web_view/shim/guest_redirect.html"; 94 "/extensions/platform_apps/web_view/shim/guest_redirect.html";
94 95
95 class EmptyHttpResponse : public net::test_server::HttpResponse { 96 class EmptyHttpResponse : public net::test_server::HttpResponse {
96 public: 97 public:
97 std::string ToResponseString() const override { return std::string(); } 98 std::string ToResponseString() const override { return std::string(); }
98 }; 99 };
99 100
100 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate { 101 class TestInterstitialPageDelegate : public content::InterstitialPageDelegate {
101 public: 102 public:
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 250
250 private: 251 private:
251 bool requested_; 252 bool requested_;
252 bool checked_; 253 bool checked_;
253 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_; 254 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_;
254 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_; 255 scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_;
255 256
256 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate); 257 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate);
257 }; 258 };
258 259
259 class MockWebViewGuestDelegate : public extensions::WebViewGuestDelegate {
260 public:
261 explicit MockWebViewGuestDelegate(extensions::WebViewGuest* web_view_guest)
262 : web_view_guest_(web_view_guest), clear_cache_called_(false) {}
263 ~MockWebViewGuestDelegate() override {}
264
265 // WebViewGuestDelegate implementation.
266 void ClearCache(base::Time remove_since,
267 const base::Closure& callback) override {
268 clear_cache_called_ = true;
269 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
270 }
271 bool HandleContextMenu(const content::ContextMenuParams& params) override {
272 return false;
273 }
274 void OnAttachWebViewHelpers(content::WebContents* contents) override {}
275 void OnDidCommitProvisionalLoadForFrame(bool is_main_frame) override {}
276 void OnDidInitialize() override {}
277 void OnDocumentLoadedInFrame(
278 content::RenderFrameHost* render_frame_host) override {}
279 void OnGuestDestroyed() override {}
280 void OnShowContextMenu(
281 int request_id,
282 const WebViewGuestDelegate::MenuItemVector* items) override {}
283
284 bool clear_cache_called() { return clear_cache_called_; }
285
286 private:
287 extensions::WebViewGuest* web_view_guest_;
288 bool clear_cache_called_;
289
290 DISALLOW_COPY_AND_ASSIGN(MockWebViewGuestDelegate);
291 };
292
293 // This class intercepts download request from the guest. 260 // This class intercepts download request from the guest.
294 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate { 261 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate {
295 public: 262 public:
296 explicit MockDownloadWebContentsDelegate( 263 explicit MockDownloadWebContentsDelegate(
297 content::WebContentsDelegate* orig_delegate) 264 content::WebContentsDelegate* orig_delegate)
298 : orig_delegate_(orig_delegate), 265 : orig_delegate_(orig_delegate),
299 waiting_for_decision_(false), 266 waiting_for_decision_(false),
300 expect_allow_(false), 267 expect_allow_(false),
301 decision_made_(false), 268 decision_made_(false),
302 last_download_allowed_(false) {} 269 last_download_allowed_(false) {}
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 new net::test_server::BasicHttpResponse); 568 new net::test_server::BasicHttpResponse);
602 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); 569 http_response->set_code(net::HTTP_MOVED_PERMANENTLY);
603 http_response->AddCustomHeader("Location", redirect_target.spec()); 570 http_response->AddCustomHeader("Location", redirect_target.spec());
604 return http_response.Pass(); 571 return http_response.Pass();
605 } 572 }
606 573
607 // Handles |request| by serving an empty response. 574 // Handles |request| by serving an empty response.
608 static scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler( 575 static scoped_ptr<net::test_server::HttpResponse> EmptyResponseHandler(
609 const std::string& path, 576 const std::string& path,
610 const net::test_server::HttpRequest& request) { 577 const net::test_server::HttpRequest& request) {
611 if (StartsWithASCII(path, request.relative_url, true)) { 578 if (StartsWithASCII(path, request.relative_url, true))
612 return scoped_ptr<net::test_server::HttpResponse>( 579 return scoped_ptr<net::test_server::HttpResponse>(new EmptyHttpResponse);
613 new EmptyHttpResponse);
614 }
615 580
616 return scoped_ptr<net::test_server::HttpResponse>(); 581 return scoped_ptr<net::test_server::HttpResponse>();
617 } 582 }
618 583
584 // Handles |request| by serving cache-able response.
585 static scoped_ptr<net::test_server::HttpResponse> CacheControlResponseHandler(
586 const std::string& path,
587 const net::test_server::HttpRequest& request) {
588 if (!StartsWithASCII(path, request.relative_url, true))
589 return scoped_ptr<net::test_server::HttpResponse>();
590
591 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
592 new net::test_server::BasicHttpResponse);
593 http_response->AddCustomHeader("Cache-control", "max-age=3600");
594 http_response->set_content_type("text/plain");
595 http_response->set_content("dummy text");
596 return http_response.Pass();
597 }
598
619 // Shortcut to return the current MenuManager. 599 // Shortcut to return the current MenuManager.
620 extensions::MenuManager* menu_manager() { 600 extensions::MenuManager* menu_manager() {
621 return extensions::MenuManager::Get(browser()->profile()); 601 return extensions::MenuManager::Get(browser()->profile());
622 } 602 }
623 603
624 // This gets all the items that any extension has registered for possible 604 // This gets all the items that any extension has registered for possible
625 // inclusion in context menus. 605 // inclusion in context menus.
626 MenuItem::List GetItems() { 606 MenuItem::List GetItems() {
627 MenuItem::List result; 607 MenuItem::List result;
628 std::set<MenuItem::ExtensionKey> extension_ids = 608 std::set<MenuItem::ExtensionKey> extension_ids =
(...skipping 26 matching lines...) Expand all
655 embedded_test_server()->GetURL(kRedirectResponseFullPath))); 635 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
656 636
657 embedded_test_server()->RegisterRequestHandler( 637 embedded_test_server()->RegisterRequestHandler(
658 base::Bind(&WebViewTest::EmptyResponseHandler, kEmptyResponsePath)); 638 base::Bind(&WebViewTest::EmptyResponseHandler, kEmptyResponsePath));
659 639
660 embedded_test_server()->RegisterRequestHandler( 640 embedded_test_server()->RegisterRequestHandler(
661 base::Bind( 641 base::Bind(
662 &WebViewTest::UserAgentResponseHandler, 642 &WebViewTest::UserAgentResponseHandler,
663 kUserAgentRedirectResponsePath, 643 kUserAgentRedirectResponsePath,
664 embedded_test_server()->GetURL(kRedirectResponseFullPath))); 644 embedded_test_server()->GetURL(kRedirectResponseFullPath)));
645
646 embedded_test_server()->RegisterRequestHandler(base::Bind(
647 &WebViewTest::CacheControlResponseHandler, kCacheResponsePath));
665 } 648 }
666 649
667 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched"); 650 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
668 651
669 // Flush any pending events to make sure we start with a clean slate. 652 // Flush any pending events to make sure we start with a clean slate.
670 content::RunAllPendingInMessageLoop(); 653 content::RunAllPendingInMessageLoop();
671 654
672 content::WebContents* embedder_web_contents = 655 content::WebContents* embedder_web_contents =
673 GetFirstAppWindowWebContents(); 656 GetFirstAppWindowWebContents();
674 if (!embedder_web_contents) { 657 if (!embedder_web_contents) {
(...skipping 1752 matching lines...) Expand 10 before | Expand all | Expand 10 after
2427 return; 2410 return;
2428 #endif 2411 #endif
2429 2412
2430 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages. 2413 ASSERT_TRUE(StartEmbeddedTestServer()); // For serving guest pages.
2431 ASSERT_TRUE(RunPlatformAppTestWithArg( 2414 ASSERT_TRUE(RunPlatformAppTestWithArg(
2432 "platform_apps/web_view/common", "cleardata")) 2415 "platform_apps/web_view/common", "cleardata"))
2433 << message_; 2416 << message_;
2434 } 2417 }
2435 2418
2436 IN_PROC_BROWSER_TEST_F(WebViewTest, ClearDataCache) { 2419 IN_PROC_BROWSER_TEST_F(WebViewTest, ClearDataCache) {
2437 LoadAppWithGuest("web_view/clear_data_cache"); 2420 TestHelper("testClearCache", "web_view/clear_data_cache", NEEDS_TEST_SERVER);
2438 content::WebContents* guest_web_contents = GetGuestWebContents();
2439 auto guest = extensions::WebViewGuest::FromWebContents(guest_web_contents);
2440 ASSERT_TRUE(guest);
2441 scoped_ptr<extensions::WebViewGuestDelegate> mock_web_view_guest_delegate(
2442 new MockWebViewGuestDelegate(guest));
2443 scoped_ptr<extensions::WebViewGuestDelegate> orig_web_view_guest_delegate =
2444 guest->SetDelegateForTesting(mock_web_view_guest_delegate.Pass());
2445
2446 ASSERT_TRUE(GetEmbedderWebContents());
2447 ExtensionTestMessageListener clear_data_done_listener(
2448 "WebViewTest.CLEAR_DATA_DONE", false);
2449 EXPECT_TRUE(content::ExecuteScript(
2450 GetEmbedderWebContents(), base::StringPrintf("testClearDataCache()")));
2451 EXPECT_TRUE(clear_data_done_listener.WaitUntilSatisfied());
2452
2453 // Reset delegate back to original once we're done mocking.
2454 mock_web_view_guest_delegate =
2455 guest->SetDelegateForTesting(orig_web_view_guest_delegate.Pass());
2456 } 2421 }
2457 2422
2458 // This test is disabled on Win due to being flaky. http://crbug.com/294592 2423 // This test is disabled on Win due to being flaky. http://crbug.com/294592
2459 #if defined(OS_WIN) 2424 #if defined(OS_WIN)
2460 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage 2425 #define MAYBE_ConsoleMessage DISABLED_ConsoleMessage
2461 #else 2426 #else
2462 #define MAYBE_ConsoleMessage ConsoleMessage 2427 #define MAYBE_ConsoleMessage ConsoleMessage
2463 #endif 2428 #endif
2464 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) { 2429 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_ConsoleMessage) {
2465 ASSERT_TRUE(RunPlatformAppTestWithArg( 2430 ASSERT_TRUE(RunPlatformAppTestWithArg(
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
2809 IN_PROC_BROWSER_TEST_F(WebViewTest, AllowTransparencyAndAllowScalingPropagate) { 2774 IN_PROC_BROWSER_TEST_F(WebViewTest, AllowTransparencyAndAllowScalingPropagate) {
2810 LoadAppWithGuest("web_view/simple"); 2775 LoadAppWithGuest("web_view/simple");
2811 2776
2812 ASSERT_TRUE(!!GetGuestWebContents()); 2777 ASSERT_TRUE(!!GetGuestWebContents());
2813 extensions::WebViewGuest* guest = 2778 extensions::WebViewGuest* guest =
2814 extensions::WebViewGuest::FromWebContents(GetGuestWebContents()); 2779 extensions::WebViewGuest::FromWebContents(GetGuestWebContents());
2815 ASSERT_TRUE(guest->allow_transparency()); 2780 ASSERT_TRUE(guest->allow_transparency());
2816 ASSERT_TRUE(guest->allow_scaling()); 2781 ASSERT_TRUE(guest->allow_scaling());
2817 } 2782 }
2818 2783
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698