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 <list> |
| 6 #include <set> |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/stringprintf.h" |
5 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_browser_main.h" |
| 15 #include "chrome/browser/chrome_browser_main_extra_parts.h" |
| 16 #include "chrome/browser/chrome_content_browser_client.h" |
6 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 17 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 18 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
10 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 22 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
11 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
| 25 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
| 30 #include "content/public/browser/resource_controller.h" |
| 31 #include "content/public/browser/resource_dispatcher_host.h" |
| 32 #include "content/public/browser/resource_throttle.h" |
16 #include "content/public/browser/web_contents.h" | 33 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/context_menu_params.h" | 34 #include "content/public/common/context_menu_params.h" |
18 #include "content/public/test/browser_test_utils.h" | 35 #include "content/public/test/browser_test_utils.h" |
19 #include "net/base/mock_host_resolver.h" | 36 #include "net/base/mock_host_resolver.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 39 #include "webkit/glue/resource_type.h" |
22 | 40 |
23 using content::WebContents; | 41 using content::WebContents; |
24 | 42 |
25 namespace extensions { | 43 namespace extensions { |
26 | 44 |
27 namespace { | 45 namespace { |
28 | 46 |
| 47 // An UI-less RenderViewContextMenu. |
29 class TestRenderViewContextMenu : public RenderViewContextMenu { | 48 class TestRenderViewContextMenu : public RenderViewContextMenu { |
30 public: | 49 public: |
31 TestRenderViewContextMenu(WebContents* web_contents, | 50 TestRenderViewContextMenu(WebContents* web_contents, |
32 const content::ContextMenuParams& params) | 51 const content::ContextMenuParams& params) |
33 : RenderViewContextMenu(web_contents, params) { | 52 : RenderViewContextMenu(web_contents, params) { |
34 } | 53 } |
35 virtual ~TestRenderViewContextMenu() {} | 54 virtual ~TestRenderViewContextMenu() {} |
36 | 55 |
37 private: | 56 private: |
38 virtual void PlatformInit() {} | 57 virtual void PlatformInit() {} |
39 virtual void PlatformCancel() {} | 58 virtual void PlatformCancel() {} |
40 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { | 59 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { |
41 return false; | 60 return false; |
42 } | 61 } |
43 | 62 |
44 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); | 63 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
45 }; | 64 }; |
46 | 65 |
| 66 |
| 67 // This class can defer requests for arbitrary URLs. |
| 68 class TestNavigationListener |
| 69 : public base::RefCountedThreadSafe<TestNavigationListener> { |
| 70 public: |
| 71 TestNavigationListener() {} |
| 72 |
| 73 // Add |url| to the set of URLs we should delay. |
| 74 void DelayRequestsForURL(const GURL& url) { |
| 75 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
| 76 content::BrowserThread::PostTask( |
| 77 content::BrowserThread::IO, |
| 78 FROM_HERE, |
| 79 base::Bind(&TestNavigationListener::DelayRequestsForURL, this, url)); |
| 80 return; |
| 81 } |
| 82 urls_to_delay_.insert(url); |
| 83 } |
| 84 |
| 85 // Resume all deferred requests. |
| 86 void ResumeAll() { |
| 87 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
| 88 content::BrowserThread::PostTask( |
| 89 content::BrowserThread::IO, |
| 90 FROM_HERE, |
| 91 base::Bind(&TestNavigationListener::ResumeAll, this)); |
| 92 return; |
| 93 } |
| 94 WeakThrottleList::const_iterator it; |
| 95 for (it = throttles_.begin(); it != throttles_.end(); ++it) { |
| 96 if (*it) |
| 97 (*it)->Resume(); |
| 98 } |
| 99 throttles_.clear(); |
| 100 } |
| 101 |
| 102 // Constructs a ResourceThrottle if the request for |url| should be held. |
| 103 // |
| 104 // Needs to be invoked on the IO thread. |
| 105 content::ResourceThrottle* CreateResourceThrottle( |
| 106 const GURL& url, |
| 107 ResourceType::Type resource_type) { |
| 108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 109 if (urls_to_delay_.find(url) == urls_to_delay_.end()) |
| 110 return NULL; |
| 111 |
| 112 Throttle* throttle = new Throttle(); |
| 113 throttles_.push_back(throttle->AsWeakPtr()); |
| 114 return throttle; |
| 115 } |
| 116 |
| 117 private: |
| 118 friend class base::RefCountedThreadSafe<TestNavigationListener>; |
| 119 |
| 120 virtual ~TestNavigationListener() {} |
| 121 |
| 122 // Stores a throttle per URL request that we have delayed. |
| 123 class Throttle : public content::ResourceThrottle, |
| 124 public base::SupportsWeakPtr<Throttle> { |
| 125 public: |
| 126 void Resume() { |
| 127 controller()->Resume(); |
| 128 } |
| 129 |
| 130 // content::ResourceThrottle implementation. |
| 131 virtual void WillStartRequest(bool* defer) { |
| 132 *defer = true; |
| 133 } |
| 134 }; |
| 135 typedef base::WeakPtr<Throttle> WeakThrottle; |
| 136 typedef std::list<WeakThrottle> WeakThrottleList; |
| 137 WeakThrottleList throttles_; |
| 138 |
| 139 // The set of URLs to be delayed. |
| 140 std::set<GURL> urls_to_delay_; |
| 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(TestNavigationListener); |
| 143 }; |
| 144 |
| 145 // Waits for a WC to be created. Once it starts loading |delay_url| (after at |
| 146 // least the first navigation has committed), it delays the load, executes |
| 147 // |script| in the last committed RVH and resumes the load when |until_url| |
| 148 // commits. This class expects |script| to trigger the load of |until_url|. |
| 149 class DelayLoadStartAndExecuteJavascript |
| 150 : public content::NotificationObserver, |
| 151 public content::WebContentsObserver { |
| 152 public: |
| 153 DelayLoadStartAndExecuteJavascript( |
| 154 TestNavigationListener* test_navigation_listener, |
| 155 const GURL& delay_url, |
| 156 const std::string& script, |
| 157 const GURL& until_url) |
| 158 : content::WebContentsObserver(), |
| 159 test_navigation_listener_(test_navigation_listener), |
| 160 delay_url_(delay_url), |
| 161 until_url_(until_url), |
| 162 script_(script), |
| 163 script_was_executed_(false), |
| 164 rvh_(NULL) { |
| 165 registrar_.Add(this, |
| 166 chrome::NOTIFICATION_TAB_ADDED, |
| 167 content::NotificationService::AllSources()); |
| 168 test_navigation_listener_->DelayRequestsForURL(delay_url_); |
| 169 } |
| 170 virtual ~DelayLoadStartAndExecuteJavascript() {} |
| 171 |
| 172 virtual void Observe(int type, |
| 173 const content::NotificationSource& source, |
| 174 const content::NotificationDetails& details) OVERRIDE { |
| 175 if (type != chrome::NOTIFICATION_TAB_ADDED) { |
| 176 NOTREACHED(); |
| 177 return; |
| 178 } |
| 179 content::WebContentsObserver::Observe( |
| 180 content::Details<content::WebContents>(details).ptr()); |
| 181 registrar_.RemoveAll(); |
| 182 } |
| 183 |
| 184 virtual void DidStartProvisionalLoadForFrame( |
| 185 int64 frame_id, |
| 186 bool is_main_frame, |
| 187 const GURL& validated_url, |
| 188 bool is_error_page, |
| 189 content::RenderViewHost* render_view_host) OVERRIDE { |
| 190 if (validated_url != delay_url_ || !rvh_) |
| 191 return; |
| 192 |
| 193 rvh_->ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(script_)); |
| 194 script_was_executed_ = true; |
| 195 } |
| 196 |
| 197 virtual void DidCommitProvisionalLoadForFrame( |
| 198 int64 frame_id, |
| 199 bool is_main_frame, |
| 200 const GURL& url, |
| 201 content::PageTransition transition_type, |
| 202 content::RenderViewHost* render_view_host) OVERRIDE { |
| 203 if (script_was_executed_ && url == until_url_) { |
| 204 content::WebContentsObserver::Observe(NULL); |
| 205 test_navigation_listener_->ResumeAll(); |
| 206 } |
| 207 rvh_ = render_view_host; |
| 208 } |
| 209 |
| 210 private: |
| 211 content::NotificationRegistrar registrar_; |
| 212 |
| 213 scoped_refptr<TestNavigationListener> test_navigation_listener_; |
| 214 |
| 215 GURL delay_url_; |
| 216 GURL until_url_; |
| 217 std::string script_; |
| 218 bool script_was_executed_; |
| 219 content::RenderViewHost* rvh_; |
| 220 |
| 221 DISALLOW_COPY_AND_ASSIGN(DelayLoadStartAndExecuteJavascript); |
| 222 }; |
| 223 |
| 224 // A ResourceDispatcherHostDelegate that adds a TestNavigationObserver. |
| 225 class TestResourceDispatcherHostDelegate |
| 226 : public ChromeResourceDispatcherHostDelegate { |
| 227 public: |
| 228 TestResourceDispatcherHostDelegate( |
| 229 prerender::PrerenderTracker* prerender_tracker, |
| 230 TestNavigationListener* test_navigation_listener) |
| 231 : ChromeResourceDispatcherHostDelegate(prerender_tracker), |
| 232 test_navigation_listener_(test_navigation_listener) { |
| 233 } |
| 234 virtual ~TestResourceDispatcherHostDelegate() {} |
| 235 |
| 236 virtual void RequestBeginning( |
| 237 net::URLRequest* request, |
| 238 content::ResourceContext* resource_context, |
| 239 ResourceType::Type resource_type, |
| 240 int child_id, |
| 241 int route_id, |
| 242 bool is_continuation_of_transferred_request, |
| 243 ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE { |
| 244 ChromeResourceDispatcherHostDelegate::RequestBeginning( |
| 245 request, |
| 246 resource_context, |
| 247 resource_type, |
| 248 child_id, |
| 249 route_id, |
| 250 is_continuation_of_transferred_request, |
| 251 throttles); |
| 252 content::ResourceThrottle* throttle = |
| 253 test_navigation_listener_->CreateResourceThrottle(request->url(), |
| 254 resource_type); |
| 255 if (throttle) |
| 256 throttles->push_back(throttle); |
| 257 } |
| 258 |
| 259 private: |
| 260 scoped_refptr<TestNavigationListener> test_navigation_listener_; |
| 261 |
| 262 DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcherHostDelegate); |
| 263 }; |
| 264 |
| 265 // Used to manage the lifetime of the TestResourceDispatcherHostDelegate which |
| 266 // needs to be deleted before the threads are stopped. |
| 267 class TestBrowserMainExtraParts : public ChromeBrowserMainExtraParts { |
| 268 public: |
| 269 explicit TestBrowserMainExtraParts( |
| 270 TestNavigationListener* test_navigation_listener) |
| 271 : test_navigation_listener_(test_navigation_listener) { |
| 272 } |
| 273 virtual ~TestBrowserMainExtraParts() {} |
| 274 |
| 275 TestResourceDispatcherHostDelegate* resource_dispatcher_host_delegate() { |
| 276 if (!resource_dispatcher_host_delegate_.get()) { |
| 277 resource_dispatcher_host_delegate_.reset( |
| 278 new TestResourceDispatcherHostDelegate( |
| 279 g_browser_process->prerender_tracker(), |
| 280 test_navigation_listener_.get())); |
| 281 } |
| 282 return resource_dispatcher_host_delegate_.get(); |
| 283 } |
| 284 |
| 285 // ChromeBrowserMainExtraParts implementation. |
| 286 virtual void PostMainMessageLoopRun() OVERRIDE { |
| 287 resource_dispatcher_host_delegate_.reset(); |
| 288 } |
| 289 |
| 290 private: |
| 291 scoped_refptr<TestNavigationListener> test_navigation_listener_; |
| 292 scoped_ptr<TestResourceDispatcherHostDelegate> |
| 293 resource_dispatcher_host_delegate_; |
| 294 |
| 295 DISALLOW_COPY_AND_ASSIGN(TestBrowserMainExtraParts); |
| 296 }; |
| 297 |
| 298 // A ContentBrowserClient that doesn't forward the RDH created signal. |
| 299 class TestContentBrowserClient : public chrome::ChromeContentBrowserClient { |
| 300 public: |
| 301 explicit TestContentBrowserClient( |
| 302 TestNavigationListener* test_navigation_listener) |
| 303 : test_navigation_listener_(test_navigation_listener) { |
| 304 } |
| 305 virtual ~TestContentBrowserClient() {} |
| 306 |
| 307 virtual void ResourceDispatcherHostCreated() OVERRIDE { |
| 308 // Don't invoke ChromeContentBrowserClient::ResourceDispatcherHostCreated. |
| 309 // It would notify BrowserProcessImpl which would create a |
| 310 // ChromeResourceDispatcherHostDelegate and other objects. Not creating |
| 311 // other objects might turn out to be a problem in the future. |
| 312 content::ResourceDispatcherHost::Get()->SetDelegate( |
| 313 browser_main_extra_parts_->resource_dispatcher_host_delegate()); |
| 314 } |
| 315 |
| 316 virtual content::BrowserMainParts* CreateBrowserMainParts( |
| 317 const content::MainFunctionParams& parameters) OVERRIDE { |
| 318 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>( |
| 319 ChromeContentBrowserClient::CreateBrowserMainParts(parameters)); |
| 320 |
| 321 browser_main_extra_parts_ = |
| 322 new TestBrowserMainExtraParts(test_navigation_listener_.get()); |
| 323 main_parts->AddParts(browser_main_extra_parts_); |
| 324 return main_parts; |
| 325 } |
| 326 |
| 327 private: |
| 328 scoped_refptr<TestNavigationListener> test_navigation_listener_; |
| 329 TestBrowserMainExtraParts* browser_main_extra_parts_; |
| 330 |
| 331 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient); |
| 332 }; |
| 333 |
47 } // namespace | 334 } // namespace |
48 | 335 |
49 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigation) { | 336 class WebNavigationApiTest : public ExtensionApiTest { |
50 FrameNavigationState::set_allow_extension_scheme(true); | 337 public: |
51 | 338 WebNavigationApiTest() {} |
52 CommandLine::ForCurrentProcess()->AppendSwitch( | 339 virtual ~WebNavigationApiTest() {} |
53 switches::kAllowLegacyExtensionManifests); | 340 |
54 | 341 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 342 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 343 |
| 344 test_navigation_listener_ = new TestNavigationListener(); |
| 345 content_browser_client_.reset( |
| 346 new TestContentBrowserClient(test_navigation_listener_.get())); |
| 347 original_content_browser_client_ = content::GetContentClient()->browser(); |
| 348 content::GetContentClient()->set_browser_for_testing( |
| 349 content_browser_client_.get()); |
| 350 |
| 351 FrameNavigationState::set_allow_extension_scheme(true); |
| 352 |
| 353 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 354 switches::kAllowLegacyExtensionManifests); |
| 355 |
| 356 host_resolver()->AddRule("*", "127.0.0.1"); |
| 357 ASSERT_TRUE(StartTestServer()); |
| 358 } |
| 359 |
| 360 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 361 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); |
| 362 content::GetContentClient()->set_browser_for_testing( |
| 363 original_content_browser_client_); |
| 364 } |
| 365 |
| 366 TestNavigationListener* test_navigation_listener() { |
| 367 return test_navigation_listener_.get(); |
| 368 } |
| 369 |
| 370 private: |
| 371 scoped_refptr<TestNavigationListener> test_navigation_listener_; |
| 372 scoped_ptr<TestContentBrowserClient> content_browser_client_; |
| 373 content::ContentBrowserClient* original_content_browser_client_; |
| 374 |
| 375 DISALLOW_COPY_AND_ASSIGN(WebNavigationApiTest); |
| 376 }; |
| 377 |
| 378 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Api) { |
55 ASSERT_TRUE( | 379 ASSERT_TRUE( |
56 RunExtensionSubtest("webnavigation", "test_api.html")) << message_; | 380 RunExtensionSubtest("webnavigation", "test_api.html")) << message_; |
57 } | 381 } |
58 | 382 |
59 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationGetFrame) { | 383 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, GetFrame) { |
60 FrameNavigationState::set_allow_extension_scheme(true); | |
61 | |
62 CommandLine::ForCurrentProcess()->AppendSwitch( | |
63 switches::kAllowLegacyExtensionManifests); | |
64 | |
65 ASSERT_TRUE( | 384 ASSERT_TRUE( |
66 RunExtensionSubtest("webnavigation", "test_getFrame.html")) << message_; | 385 RunExtensionSubtest("webnavigation", "test_getFrame.html")) << message_; |
67 } | 386 } |
68 | 387 |
69 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationClientRedirect) { | 388 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ClientRedirect) { |
70 FrameNavigationState::set_allow_extension_scheme(true); | |
71 | |
72 CommandLine::ForCurrentProcess()->AppendSwitch( | |
73 switches::kAllowLegacyExtensionManifests); | |
74 | |
75 ASSERT_TRUE( | 389 ASSERT_TRUE( |
76 RunExtensionSubtest("webnavigation", "test_clientRedirect.html")) | 390 RunExtensionSubtest("webnavigation", "test_clientRedirect.html")) |
77 << message_; | 391 << message_; |
78 } | 392 } |
79 | 393 |
80 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationServerRedirect) { | 394 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ServerRedirect) { |
81 FrameNavigationState::set_allow_extension_scheme(true); | |
82 host_resolver()->AddRule("*", "127.0.0.1"); | |
83 ASSERT_TRUE(StartTestServer()); | |
84 | |
85 CommandLine::ForCurrentProcess()->AppendSwitch( | |
86 switches::kAllowLegacyExtensionManifests); | |
87 | |
88 ASSERT_TRUE( | 395 ASSERT_TRUE( |
89 RunExtensionSubtest("webnavigation", "test_serverRedirect.html")) | 396 RunExtensionSubtest("webnavigation", "test_serverRedirect.html")) |
90 << message_; | 397 << message_; |
91 } | 398 } |
92 | 399 |
93 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationForwardBack) { | 400 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ForwardBack) { |
94 FrameNavigationState::set_allow_extension_scheme(true); | |
95 | |
96 CommandLine::ForCurrentProcess()->AppendSwitch( | |
97 switches::kAllowLegacyExtensionManifests); | |
98 | |
99 ASSERT_TRUE( | 401 ASSERT_TRUE( |
100 RunExtensionSubtest("webnavigation", "test_forwardBack.html")) | 402 RunExtensionSubtest("webnavigation", "test_forwardBack.html")) |
101 << message_; | 403 << message_; |
102 } | 404 } |
103 | 405 |
104 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationIFrame) { | 406 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, IFrame) { |
105 FrameNavigationState::set_allow_extension_scheme(true); | |
106 | |
107 CommandLine::ForCurrentProcess()->AppendSwitch( | |
108 switches::kAllowLegacyExtensionManifests); | |
109 | |
110 ASSERT_TRUE( | 407 ASSERT_TRUE( |
111 RunExtensionSubtest("webnavigation", "test_iframe.html")) << message_; | 408 RunExtensionSubtest("webnavigation", "test_iframe.html")) << message_; |
112 } | 409 } |
113 | 410 |
114 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationOpenTab) { | 411 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, OpenTab) { |
115 FrameNavigationState::set_allow_extension_scheme(true); | |
116 | |
117 CommandLine::ForCurrentProcess()->AppendSwitch( | |
118 switches::kAllowLegacyExtensionManifests); | |
119 | |
120 ASSERT_TRUE( | 412 ASSERT_TRUE( |
121 RunExtensionSubtest("webnavigation", "test_openTab.html")) << message_; | 413 RunExtensionSubtest("webnavigation", "test_openTab.html")) << message_; |
122 } | 414 } |
123 | 415 |
124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationReferenceFragment) { | 416 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, ReferenceFragment) { |
125 FrameNavigationState::set_allow_extension_scheme(true); | |
126 | |
127 CommandLine::ForCurrentProcess()->AppendSwitch( | |
128 switches::kAllowLegacyExtensionManifests); | |
129 | |
130 ASSERT_TRUE( | 417 ASSERT_TRUE( |
131 RunExtensionSubtest("webnavigation", "test_referenceFragment.html")) | 418 RunExtensionSubtest("webnavigation", "test_referenceFragment.html")) |
132 << message_; | 419 << message_; |
133 } | 420 } |
134 | 421 |
135 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationSimpleLoad) { | 422 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, SimpleLoad) { |
136 FrameNavigationState::set_allow_extension_scheme(true); | |
137 | |
138 CommandLine::ForCurrentProcess()->AppendSwitch( | |
139 switches::kAllowLegacyExtensionManifests); | |
140 | |
141 ASSERT_TRUE( | 423 ASSERT_TRUE( |
142 RunExtensionSubtest("webnavigation", "test_simpleLoad.html")) << message_; | 424 RunExtensionSubtest("webnavigation", "test_simpleLoad.html")) << message_; |
143 } | 425 } |
144 | 426 |
145 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationFailures) { | 427 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Failures) { |
146 FrameNavigationState::set_allow_extension_scheme(true); | |
147 | |
148 CommandLine::ForCurrentProcess()->AppendSwitch( | |
149 switches::kAllowLegacyExtensionManifests); | |
150 | |
151 ASSERT_TRUE( | 428 ASSERT_TRUE( |
152 RunExtensionSubtest("webnavigation", "test_failures.html")) << message_; | 429 RunExtensionSubtest("webnavigation", "test_failures.html")) << message_; |
153 } | 430 } |
154 | 431 |
155 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationFilteredTest) { | 432 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, FilteredTest) { |
156 FrameNavigationState::set_allow_extension_scheme(true); | |
157 | |
158 CommandLine::ForCurrentProcess()->AppendSwitch( | |
159 switches::kAllowLegacyExtensionManifests); | |
160 | |
161 ASSERT_TRUE( | 433 ASSERT_TRUE( |
162 RunExtensionSubtest("webnavigation", "test_filtered.html")) << message_; | 434 RunExtensionSubtest("webnavigation", "test_filtered.html")) << message_; |
163 } | 435 } |
164 | 436 |
165 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationUserAction) { | 437 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, UserAction) { |
166 FrameNavigationState::set_allow_extension_scheme(true); | |
167 | |
168 CommandLine::ForCurrentProcess()->AppendSwitch( | |
169 switches::kAllowLegacyExtensionManifests); | |
170 | |
171 // Wait for the extension to set itself up and return control to us. | 438 // Wait for the extension to set itself up and return control to us. |
172 ASSERT_TRUE( | 439 ASSERT_TRUE( |
173 RunExtensionSubtest("webnavigation", "test_userAction.html")) << message_; | 440 RunExtensionSubtest("webnavigation", "test_userAction.html")) << message_; |
174 | 441 |
175 WebContents* tab = chrome::GetActiveWebContents(browser()); | 442 WebContents* tab = chrome::GetActiveWebContents(browser()); |
176 content::WaitForLoadStop(tab); | 443 content::WaitForLoadStop(tab); |
177 | 444 |
178 ResultCatcher catcher; | 445 ResultCatcher catcher; |
179 | 446 |
180 ExtensionService* service = browser()->profile()->GetExtensionService(); | 447 ExtensionService* service = browser()->profile()->GetExtensionService(); |
(...skipping 12 matching lines...) Expand all Loading... |
193 frame_navigation_state().GetMainFrameID().frame_num; | 460 frame_navigation_state().GetMainFrameID().frame_num; |
194 params.link_url = extension->GetResourceURL("userAction/b.html"); | 461 params.link_url = extension->GetResourceURL("userAction/b.html"); |
195 | 462 |
196 TestRenderViewContextMenu menu(tab, params); | 463 TestRenderViewContextMenu menu(tab, params); |
197 menu.Init(); | 464 menu.Init(); |
198 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); | 465 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); |
199 | 466 |
200 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 467 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
201 } | 468 } |
202 | 469 |
203 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationRequestOpenTab) { | 470 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, RequestOpenTab) { |
204 FrameNavigationState::set_allow_extension_scheme(true); | |
205 | |
206 CommandLine::ForCurrentProcess()->AppendSwitch( | |
207 switches::kAllowLegacyExtensionManifests); | |
208 | |
209 // Wait for the extension to set itself up and return control to us. | 471 // Wait for the extension to set itself up and return control to us. |
210 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_requestOpenTab.html")) | 472 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_requestOpenTab.html")) |
211 << message_; | 473 << message_; |
212 | 474 |
213 WebContents* tab = chrome::GetActiveWebContents(browser()); | 475 WebContents* tab = chrome::GetActiveWebContents(browser()); |
214 content::WaitForLoadStop(tab); | 476 content::WaitForLoadStop(tab); |
215 | 477 |
216 ResultCatcher catcher; | 478 ResultCatcher catcher; |
217 | 479 |
218 ExtensionService* service = browser()->profile()->GetExtensionService(); | 480 ExtensionService* service = browser()->profile()->GetExtensionService(); |
(...skipping 10 matching lines...) Expand all Loading... |
229 mouse_event.x = 7; | 491 mouse_event.x = 7; |
230 mouse_event.y = 7; | 492 mouse_event.y = 7; |
231 mouse_event.clickCount = 1; | 493 mouse_event.clickCount = 1; |
232 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 494 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
233 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 495 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
234 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 496 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
235 | 497 |
236 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 498 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
237 } | 499 } |
238 | 500 |
239 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationTargetBlank) { | 501 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, TargetBlank) { |
240 FrameNavigationState::set_allow_extension_scheme(true); | |
241 ASSERT_TRUE(StartTestServer()); | |
242 | |
243 CommandLine::ForCurrentProcess()->AppendSwitch( | |
244 switches::kAllowLegacyExtensionManifests); | |
245 | |
246 // Wait for the extension to set itself up and return control to us. | 502 // Wait for the extension to set itself up and return control to us. |
247 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_targetBlank.html")) | 503 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_targetBlank.html")) |
248 << message_; | 504 << message_; |
249 | 505 |
250 WebContents* tab = chrome::GetActiveWebContents(browser()); | 506 WebContents* tab = chrome::GetActiveWebContents(browser()); |
251 content::WaitForLoadStop(tab); | 507 content::WaitForLoadStop(tab); |
252 | 508 |
253 ResultCatcher catcher; | 509 ResultCatcher catcher; |
254 | 510 |
255 GURL url = test_server()->GetURL( | 511 GURL url = test_server()->GetURL( |
(...skipping 10 matching lines...) Expand all Loading... |
266 mouse_event.x = 7; | 522 mouse_event.x = 7; |
267 mouse_event.y = 7; | 523 mouse_event.y = 7; |
268 mouse_event.clickCount = 1; | 524 mouse_event.clickCount = 1; |
269 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 525 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
270 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 526 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
271 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 527 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
272 | 528 |
273 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 529 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
274 } | 530 } |
275 | 531 |
276 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationTargetBlankIncognito) { | 532 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, TargetBlankIncognito) { |
277 FrameNavigationState::set_allow_extension_scheme(true); | |
278 ASSERT_TRUE(StartTestServer()); | |
279 | |
280 CommandLine::ForCurrentProcess()->AppendSwitch( | |
281 switches::kAllowLegacyExtensionManifests); | |
282 | |
283 // Wait for the extension to set itself up and return control to us. | 533 // Wait for the extension to set itself up and return control to us. |
284 ASSERT_TRUE(RunExtensionSubtest( | 534 ASSERT_TRUE(RunExtensionSubtest( |
285 "webnavigation", "test_targetBlank.html", | 535 "webnavigation", "test_targetBlank.html", |
286 ExtensionApiTest::kFlagEnableIncognito)) << message_; | 536 ExtensionApiTest::kFlagEnableIncognito)) << message_; |
287 | 537 |
288 ResultCatcher catcher; | 538 ResultCatcher catcher; |
289 | 539 |
290 GURL url = test_server()->GetURL( | 540 GURL url = test_server()->GetURL( |
291 "files/extensions/api_test/webnavigation/targetBlank/a.html"); | 541 "files/extensions/api_test/webnavigation/targetBlank/a.html"); |
292 | 542 |
293 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( | 543 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( |
294 browser()->profile(), url); | 544 browser()->profile(), url); |
295 WebContents* tab = chrome::GetActiveWebContents(otr_browser); | 545 WebContents* tab = chrome::GetActiveWebContents(otr_browser); |
296 | 546 |
297 // There's a link with target=_blank on a.html. Click on it to open it in a | 547 // There's a link with target=_blank on a.html. Click on it to open it in a |
298 // new tab. | 548 // new tab. |
299 WebKit::WebMouseEvent mouse_event; | 549 WebKit::WebMouseEvent mouse_event; |
300 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 550 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
301 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 551 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
302 mouse_event.x = 7; | 552 mouse_event.x = 7; |
303 mouse_event.y = 7; | 553 mouse_event.y = 7; |
304 mouse_event.clickCount = 1; | 554 mouse_event.clickCount = 1; |
305 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 555 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
306 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 556 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
307 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 557 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
308 | 558 |
309 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 559 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
310 } | 560 } |
311 | 561 |
312 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationHistory) { | 562 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, History) { |
313 FrameNavigationState::set_allow_extension_scheme(true); | |
314 | |
315 CommandLine::ForCurrentProcess()->AppendSwitch( | |
316 switches::kAllowLegacyExtensionManifests); | |
317 | |
318 ASSERT_TRUE( | 563 ASSERT_TRUE( |
319 RunExtensionSubtest("webnavigation", "test_history.html")) | 564 RunExtensionSubtest("webnavigation", "test_history.html")) |
320 << message_; | 565 << message_; |
321 } | 566 } |
322 | 567 |
| 568 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcess) { |
| 569 LoadExtension(test_data_dir_.AppendASCII("webnavigation").AppendASCII("app")); |
| 570 LoadExtension(test_data_dir_.AppendASCII("webnavigation")); |
| 571 |
| 572 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| 573 const extensions::Extension* extension = |
| 574 service->GetExtensionById(last_loaded_extension_id_, false); |
| 575 |
| 576 // See crossProcess/d.html. |
| 577 DelayLoadStartAndExecuteJavascript call_script( |
| 578 test_navigation_listener(), |
| 579 test_server()->GetURL("test1"), |
| 580 "navigate2()", |
| 581 extension->GetResourceURL("crossProcess/empty.html")); |
| 582 |
| 583 // See crossProcess/e.html. |
| 584 DelayLoadStartAndExecuteJavascript call_script2( |
| 585 test_navigation_listener(), |
| 586 test_server()->GetURL("test2"), |
| 587 "updateHistory()", |
| 588 extension->GetResourceURL("crossProcess/empty.html")); |
| 589 |
| 590 // See crossProcess/f.html. |
| 591 DelayLoadStartAndExecuteJavascript call_script3( |
| 592 test_navigation_listener(), |
| 593 test_server()->GetURL("test3"), |
| 594 "updateFragment()", |
| 595 extension->GetResourceURL(base::StringPrintf( |
| 596 "crossProcess/f.html?%d#foo", |
| 597 test_server()->host_port_pair().port()))); |
| 598 |
| 599 // See crossProcess/g.html. |
| 600 DelayLoadStartAndExecuteJavascript call_script4( |
| 601 test_navigation_listener(), |
| 602 test_server()->GetURL("test4"), |
| 603 "updateFragment()", |
| 604 extension->GetResourceURL(base::StringPrintf( |
| 605 "crossProcess/g.html?%d#foo", |
| 606 test_server()->host_port_pair().port()))); |
| 607 |
| 608 // See crossProcess/h.html. |
| 609 DelayLoadStartAndExecuteJavascript call_script5( |
| 610 test_navigation_listener(), |
| 611 test_server()->GetURL("test5"), |
| 612 "updateHistory()", |
| 613 extension->GetResourceURL("crossProcess/empty.html")); |
| 614 |
| 615 // See crossProcess/i.html. |
| 616 DelayLoadStartAndExecuteJavascript call_script6( |
| 617 test_navigation_listener(), |
| 618 test_server()->GetURL("test6"), |
| 619 "updateHistory()", |
| 620 extension->GetResourceURL("crossProcess/empty.html")); |
| 621 |
| 622 ASSERT_TRUE(RunPageTest( |
| 623 extension->GetResourceURL("test_crossProcess.html").spec())) |
| 624 << message_; |
| 625 } |
| 626 |
323 } // namespace extensions | 627 } // namespace extensions |
OLD | NEW |