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

Side by Side Diff: chrome/browser/extensions/web_view_browsertest.cc

Issue 13037003: permissionrequest API for guest Download. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync @tott Created 7 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 | Annotate | Revision Log
OLDNEW
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/stringprintf.h" 5 #include "base/stringprintf.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/automation/automation_util.h" 7 #include "chrome/browser/automation/automation_util.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h" 8 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/browser/extensions/platform_app_browsertest_util.h" 9 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
10 #include "chrome/browser/prerender/prerender_link_manager.h" 10 #include "chrome/browser/prerender/prerender_link_manager.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 void WaitForSetMediaPermission() { 49 void WaitForSetMediaPermission() {
50 if (requested_) 50 if (requested_)
51 return; 51 return;
52 message_loop_runner_ = new content::MessageLoopRunner; 52 message_loop_runner_ = new content::MessageLoopRunner;
53 message_loop_runner_->Run(); 53 message_loop_runner_->Run();
54 } 54 }
55 55
56 private: 56 private:
57 bool requested_; 57 bool requested_;
58 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 58 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
59
60 DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate);
61 };
62
63 // This class intercepts download request from the guest.
64 class MockDownloadWebContentsDelegate : public content::WebContentsDelegate {
65 public:
66 explicit MockDownloadWebContentsDelegate(
67 content::WebContentsDelegate* orig_delegate)
68 : orig_delegate_(orig_delegate),
69 waiting_for_decision_(false),
70 expect_allow_(false),
71 decision_made_(false),
72 last_download_allowed_(false) {}
73 virtual ~MockDownloadWebContentsDelegate() {}
74
75 virtual void CanDownload(
76 content::RenderViewHost* render_view_host,
77 int request_id,
78 const std::string& request_method,
79 const base::Callback<void(bool)>& callback) OVERRIDE {
80 orig_delegate_->CanDownload(
81 render_view_host, request_id, request_method,
82 base::Bind(&MockDownloadWebContentsDelegate::DownloadDecided,
83 base::Unretained(this)));
84 }
85
86 void WaitForCanDownload(bool expect_allow) {
87 EXPECT_FALSE(waiting_for_decision_);
88 waiting_for_decision_ = true;
89
90 if (decision_made_) {
91 EXPECT_EQ(expect_allow, last_download_allowed_);
92 return;
93 }
94
95 expect_allow_ = expect_allow;
96 message_loop_runner_ = new content::MessageLoopRunner;
97 message_loop_runner_->Run();
98 }
99
100 void DownloadDecided(bool allow) {
101 EXPECT_FALSE(decision_made_);
102 decision_made_ = true;
103
104 if (waiting_for_decision_) {
105 EXPECT_EQ(expect_allow_, allow);
106 if (message_loop_runner_)
107 message_loop_runner_->Quit();
108 return;
109 }
110 last_download_allowed_ = allow;
111 }
112
113 void Reset() {
114 waiting_for_decision_ = false;
115 decision_made_ = false;
116 }
117
118 private:
119 content::WebContentsDelegate* orig_delegate_;
120 bool waiting_for_decision_;
121 bool expect_allow_;
122 bool decision_made_;
123 bool last_download_allowed_;
124 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
125
126 DISALLOW_COPY_AND_ASSIGN(MockDownloadWebContentsDelegate);
59 }; 127 };
60 128
61 class WebViewTest : public extensions::PlatformAppBrowserTest { 129 class WebViewTest : public extensions::PlatformAppBrowserTest {
62 protected: 130 protected:
63 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 131 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
64 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); 132 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
65 #if !defined(OS_MACOSX) 133 #if !defined(OS_MACOSX)
66 CHECK(test_launcher_utils::OverrideGLImplementation( 134 CHECK(test_launcher_utils::OverrideGLImplementation(
67 command_line, gfx::kGLImplementationOSMesaName)) << 135 command_line, gfx::kGLImplementationOSMesaName)) <<
68 "kUseGL must not be set by test framework code!"; 136 "kUseGL must not be set by test framework code!";
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 #if defined(OS_WIN) && !defined(NDEBUG) 921 #if defined(OS_WIN) && !defined(NDEBUG)
854 #define MAYBE_NewWindow DISABLED_NewWindow 922 #define MAYBE_NewWindow DISABLED_NewWindow
855 #else 923 #else
856 #define MAYBE_NewWindow NewWindow 924 #define MAYBE_NewWindow NewWindow
857 #endif 925 #endif
858 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_NewWindow) { 926 IN_PROC_BROWSER_TEST_F(WebViewTest, MAYBE_NewWindow) {
859 ASSERT_TRUE(StartTestServer()); // For serving guest pages. 927 ASSERT_TRUE(StartTestServer()); // For serving guest pages.
860 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/newwindow")) 928 ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/newwindow"))
861 << message_; 929 << message_;
862 } 930 }
931
932 IN_PROC_BROWSER_TEST_F(WebViewTest, DownloadPermission) {
933 ASSERT_TRUE(StartTestServer()); // For serving guest pages.
934 LoadAndLaunchPlatformApp("web_view/download");
935
936 GURL::Replacements replace_host;
937 std::string host_str("localhost"); // Must stay in scope with replace_host.
938 replace_host.SetHostStr(host_str);
939
940 // Grab the guest's WebContents.
941 GURL guest_url = test_server()->GetURL(
942 "files/extensions/platform_apps/web_view/download/guest.html");
943 guest_url = guest_url.ReplaceComponents(replace_host);
944 ui_test_utils::UrlLoadObserver observer(
945 guest_url, content::NotificationService::AllSources());
946 observer.Wait();
947 content::Source<content::NavigationController> source = observer.source();
948 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
949 content::WebContents* guest_web_contents = source->GetWebContents();
950
951 // Replace WebContentsDelegate with mock version so we can intercept download
952 // requests.
953 content::WebContentsDelegate* delegate = guest_web_contents->GetDelegate();
954 MockDownloadWebContentsDelegate* mock_delegate =
955 new MockDownloadWebContentsDelegate(delegate);
956 guest_web_contents->SetDelegate(mock_delegate);
957
958 // Start test.
959 // 1. Guest requests a download that its embedder denies.
960 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
961 "startDownload('download-link-1')"));
962 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
963 mock_delegate->Reset();
964
965 // 2. Guest requests a download that its embedder allows.
966 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
967 "startDownload('download-link-2')"));
968 mock_delegate->WaitForCanDownload(true); // Expect to allow.
969 mock_delegate->Reset();
970
971 // 3. Guest requests a download that its embedder ignores, this implies deny.
972 EXPECT_TRUE(content::ExecuteScript(guest_web_contents,
973 "startDownload('download-link-3')"));
974 mock_delegate->WaitForCanDownload(false); // Expect to not allow.
975 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_request_limiter.cc ('k') | chrome/browser/prerender/prerender_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698