Chromium Code Reviews| 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. The idea is that |script| triggers the load of |until_url|. | |
|
Charlie Reis
2012/08/07 21:53:05
nit: s/The idea is that |script| triggers/This cla
jochen (gone - plz use gerrit)
2012/08/08 08:31:51
Done.
| |
| 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 : chrome::ChromeContentBrowserClient(), | |
|
jam
2012/08/07 20:31:32
nit: why?
jochen (gone - plz use gerrit)
2012/08/08 08:31:51
Done.
| |
| 304 test_navigation_listener_(test_navigation_listener) { | |
| 305 } | |
| 306 virtual ~TestContentBrowserClient() {} | |
| 307 | |
| 308 virtual void ResourceDispatcherHostCreated() OVERRIDE { | |
| 309 // Don't invoke ChromeContentBrowserClient::ResourceDispatcherHostCreated. | |
| 310 // It would notify BrowserProcessImpl which would create a CRDHD and other | |
|
jam
2012/08/07 20:31:32
nit: ChromeResourceDispatcherHostDelegate since no
jochen (gone - plz use gerrit)
2012/08/08 08:31:51
Done.
| |
| 311 // objects. Not creating other objects might turn out to be a problem in the | |
| 312 // future. | |
| 313 content::ResourceDispatcherHost::Get()->SetDelegate( | |
| 314 browser_main_extra_parts_->resource_dispatcher_host_delegate()); | |
| 315 } | |
| 316 | |
| 317 virtual content::BrowserMainParts* CreateBrowserMainParts( | |
| 318 const content::MainFunctionParams& parameters) OVERRIDE { | |
| 319 ChromeBrowserMainParts* main_parts = static_cast<ChromeBrowserMainParts*>( | |
| 320 ChromeContentBrowserClient::CreateBrowserMainParts(parameters)); | |
| 321 | |
| 322 browser_main_extra_parts_ = | |
| 323 new TestBrowserMainExtraParts(test_navigation_listener_.get()); | |
| 324 main_parts->AddParts(browser_main_extra_parts_); | |
| 325 return main_parts; | |
| 326 } | |
| 327 | |
| 328 private: | |
| 329 scoped_refptr<TestNavigationListener> test_navigation_listener_; | |
| 330 TestBrowserMainExtraParts* browser_main_extra_parts_; | |
| 331 | |
| 332 DISALLOW_COPY_AND_ASSIGN(TestContentBrowserClient); | |
| 333 }; | |
| 334 | |
| 47 } // namespace | 335 } // namespace |
| 48 | 336 |
| 49 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigation) { | 337 class WebNavigationApiTest : public ExtensionApiTest { |
| 50 FrameNavigationState::set_allow_extension_scheme(true); | 338 public: |
| 51 | 339 WebNavigationApiTest() {} |
| 52 CommandLine::ForCurrentProcess()->AppendSwitch( | 340 virtual ~WebNavigationApiTest() {} |
| 53 switches::kAllowLegacyExtensionManifests); | 341 |
| 54 | 342 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 343 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
| 344 | |
| 345 test_navigation_listener_ = new TestNavigationListener(); | |
| 346 content_browser_client_.reset( | |
| 347 new TestContentBrowserClient(test_navigation_listener_.get())); | |
| 348 original_content_browser_client_ = content::GetContentClient()->browser(); | |
| 349 content::GetContentClient()->set_browser_for_testing( | |
| 350 content_browser_client_.get()); | |
| 351 | |
| 352 FrameNavigationState::set_allow_extension_scheme(true); | |
| 353 | |
| 354 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 355 switches::kAllowLegacyExtensionManifests); | |
| 356 | |
| 357 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 358 ASSERT_TRUE(StartTestServer()); | |
| 359 } | |
| 360 | |
| 361 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | |
| 362 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); | |
| 363 content::GetContentClient()->set_browser_for_testing( | |
| 364 original_content_browser_client_); | |
| 365 content_browser_client_.reset(); | |
| 366 } | |
| 367 | |
| 368 TestNavigationListener* test_navigation_listener() { | |
| 369 return test_navigation_listener_.get(); | |
| 370 } | |
| 371 | |
| 372 private: | |
| 373 scoped_refptr<TestNavigationListener> test_navigation_listener_; | |
| 374 scoped_ptr<TestContentBrowserClient> content_browser_client_; | |
| 375 content::ContentBrowserClient* original_content_browser_client_; | |
| 376 | |
| 377 DISALLOW_COPY_AND_ASSIGN(WebNavigationApiTest); | |
| 378 }; | |
| 379 | |
| 380 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, Api) { | |
| 55 ASSERT_TRUE( | 381 ASSERT_TRUE( |
| 56 RunExtensionSubtest("webnavigation", "test_api.html")) << message_; | 382 RunExtensionSubtest("webnavigation", "test_api.html")) << message_; |
| 57 } | 383 } |
| 58 | 384 |
| 59 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationGetFrame) { | 385 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( | 386 ASSERT_TRUE( |
| 66 RunExtensionSubtest("webnavigation", "test_getFrame.html")) << message_; | 387 RunExtensionSubtest("webnavigation", "test_getFrame.html")) << message_; |
| 67 } | 388 } |
| 68 | 389 |
| 69 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationClientRedirect) { | 390 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( | 391 ASSERT_TRUE( |
| 76 RunExtensionSubtest("webnavigation", "test_clientRedirect.html")) | 392 RunExtensionSubtest("webnavigation", "test_clientRedirect.html")) |
| 77 << message_; | 393 << message_; |
| 78 } | 394 } |
| 79 | 395 |
| 80 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationServerRedirect) { | 396 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( | 397 ASSERT_TRUE( |
| 89 RunExtensionSubtest("webnavigation", "test_serverRedirect.html")) | 398 RunExtensionSubtest("webnavigation", "test_serverRedirect.html")) |
| 90 << message_; | 399 << message_; |
| 91 } | 400 } |
| 92 | 401 |
| 93 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationForwardBack) { | 402 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( | 403 ASSERT_TRUE( |
| 100 RunExtensionSubtest("webnavigation", "test_forwardBack.html")) | 404 RunExtensionSubtest("webnavigation", "test_forwardBack.html")) |
| 101 << message_; | 405 << message_; |
| 102 } | 406 } |
| 103 | 407 |
| 104 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationIFrame) { | 408 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( | 409 ASSERT_TRUE( |
| 111 RunExtensionSubtest("webnavigation", "test_iframe.html")) << message_; | 410 RunExtensionSubtest("webnavigation", "test_iframe.html")) << message_; |
| 112 } | 411 } |
| 113 | 412 |
| 114 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationOpenTab) { | 413 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( | 414 ASSERT_TRUE( |
| 121 RunExtensionSubtest("webnavigation", "test_openTab.html")) << message_; | 415 RunExtensionSubtest("webnavigation", "test_openTab.html")) << message_; |
| 122 } | 416 } |
| 123 | 417 |
| 124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationReferenceFragment) { | 418 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( | 419 ASSERT_TRUE( |
| 131 RunExtensionSubtest("webnavigation", "test_referenceFragment.html")) | 420 RunExtensionSubtest("webnavigation", "test_referenceFragment.html")) |
| 132 << message_; | 421 << message_; |
| 133 } | 422 } |
| 134 | 423 |
| 135 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationSimpleLoad) { | 424 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( | 425 ASSERT_TRUE( |
| 142 RunExtensionSubtest("webnavigation", "test_simpleLoad.html")) << message_; | 426 RunExtensionSubtest("webnavigation", "test_simpleLoad.html")) << message_; |
| 143 } | 427 } |
| 144 | 428 |
| 145 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationFailures) { | 429 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( | 430 ASSERT_TRUE( |
| 152 RunExtensionSubtest("webnavigation", "test_failures.html")) << message_; | 431 RunExtensionSubtest("webnavigation", "test_failures.html")) << message_; |
| 153 } | 432 } |
| 154 | 433 |
| 155 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationFilteredTest) { | 434 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( | 435 ASSERT_TRUE( |
| 162 RunExtensionSubtest("webnavigation", "test_filtered.html")) << message_; | 436 RunExtensionSubtest("webnavigation", "test_filtered.html")) << message_; |
| 163 } | 437 } |
| 164 | 438 |
| 165 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationUserAction) { | 439 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. | 440 // Wait for the extension to set itself up and return control to us. |
| 172 ASSERT_TRUE( | 441 ASSERT_TRUE( |
| 173 RunExtensionSubtest("webnavigation", "test_userAction.html")) << message_; | 442 RunExtensionSubtest("webnavigation", "test_userAction.html")) << message_; |
| 174 | 443 |
| 175 WebContents* tab = chrome::GetActiveWebContents(browser()); | 444 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 176 content::WaitForLoadStop(tab); | 445 content::WaitForLoadStop(tab); |
| 177 | 446 |
| 178 ResultCatcher catcher; | 447 ResultCatcher catcher; |
| 179 | 448 |
| 180 ExtensionService* service = browser()->profile()->GetExtensionService(); | 449 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 193 frame_navigation_state().GetMainFrameID().frame_num; | 462 frame_navigation_state().GetMainFrameID().frame_num; |
| 194 params.link_url = extension->GetResourceURL("userAction/b.html"); | 463 params.link_url = extension->GetResourceURL("userAction/b.html"); |
| 195 | 464 |
| 196 TestRenderViewContextMenu menu(tab, params); | 465 TestRenderViewContextMenu menu(tab, params); |
| 197 menu.Init(); | 466 menu.Init(); |
| 198 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); | 467 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 199 | 468 |
| 200 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 469 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 201 } | 470 } |
| 202 | 471 |
| 203 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationRequestOpenTab) { | 472 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. | 473 // Wait for the extension to set itself up and return control to us. |
| 210 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_requestOpenTab.html")) | 474 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_requestOpenTab.html")) |
| 211 << message_; | 475 << message_; |
| 212 | 476 |
| 213 WebContents* tab = chrome::GetActiveWebContents(browser()); | 477 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 214 content::WaitForLoadStop(tab); | 478 content::WaitForLoadStop(tab); |
| 215 | 479 |
| 216 ResultCatcher catcher; | 480 ResultCatcher catcher; |
| 217 | 481 |
| 218 ExtensionService* service = browser()->profile()->GetExtensionService(); | 482 ExtensionService* service = browser()->profile()->GetExtensionService(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 229 mouse_event.x = 7; | 493 mouse_event.x = 7; |
| 230 mouse_event.y = 7; | 494 mouse_event.y = 7; |
| 231 mouse_event.clickCount = 1; | 495 mouse_event.clickCount = 1; |
| 232 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 496 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 233 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 497 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 234 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 498 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 235 | 499 |
| 236 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 500 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 237 } | 501 } |
| 238 | 502 |
| 239 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationTargetBlank) { | 503 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. | 504 // Wait for the extension to set itself up and return control to us. |
| 247 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_targetBlank.html")) | 505 ASSERT_TRUE(RunExtensionSubtest("webnavigation", "test_targetBlank.html")) |
| 248 << message_; | 506 << message_; |
| 249 | 507 |
| 250 WebContents* tab = chrome::GetActiveWebContents(browser()); | 508 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 251 content::WaitForLoadStop(tab); | 509 content::WaitForLoadStop(tab); |
| 252 | 510 |
| 253 ResultCatcher catcher; | 511 ResultCatcher catcher; |
| 254 | 512 |
| 255 GURL url = test_server()->GetURL( | 513 GURL url = test_server()->GetURL( |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 266 mouse_event.x = 7; | 524 mouse_event.x = 7; |
| 267 mouse_event.y = 7; | 525 mouse_event.y = 7; |
| 268 mouse_event.clickCount = 1; | 526 mouse_event.clickCount = 1; |
| 269 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 527 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 270 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 528 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 271 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 529 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 272 | 530 |
| 273 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 531 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 274 } | 532 } |
| 275 | 533 |
| 276 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationTargetBlankIncognito) { | 534 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. | 535 // Wait for the extension to set itself up and return control to us. |
| 284 ASSERT_TRUE(RunExtensionSubtest( | 536 ASSERT_TRUE(RunExtensionSubtest( |
| 285 "webnavigation", "test_targetBlank.html", | 537 "webnavigation", "test_targetBlank.html", |
| 286 ExtensionApiTest::kFlagEnableIncognito)) << message_; | 538 ExtensionApiTest::kFlagEnableIncognito)) << message_; |
| 287 | 539 |
| 288 ResultCatcher catcher; | 540 ResultCatcher catcher; |
| 289 | 541 |
| 290 GURL url = test_server()->GetURL( | 542 GURL url = test_server()->GetURL( |
| 291 "files/extensions/api_test/webnavigation/targetBlank/a.html"); | 543 "files/extensions/api_test/webnavigation/targetBlank/a.html"); |
| 292 | 544 |
| 293 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( | 545 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( |
| 294 browser()->profile(), url); | 546 browser()->profile(), url); |
| 295 WebContents* tab = chrome::GetActiveWebContents(otr_browser); | 547 WebContents* tab = chrome::GetActiveWebContents(otr_browser); |
| 296 | 548 |
| 297 // There's a link with target=_blank on a.html. Click on it to open it in a | 549 // There's a link with target=_blank on a.html. Click on it to open it in a |
| 298 // new tab. | 550 // new tab. |
| 299 WebKit::WebMouseEvent mouse_event; | 551 WebKit::WebMouseEvent mouse_event; |
| 300 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 552 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 301 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 553 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 302 mouse_event.x = 7; | 554 mouse_event.x = 7; |
| 303 mouse_event.y = 7; | 555 mouse_event.y = 7; |
| 304 mouse_event.clickCount = 1; | 556 mouse_event.clickCount = 1; |
| 305 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 557 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 306 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 558 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 307 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 559 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 308 | 560 |
| 309 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 561 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 310 } | 562 } |
| 311 | 563 |
| 312 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationHistory) { | 564 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( | 565 ASSERT_TRUE( |
| 319 RunExtensionSubtest("webnavigation", "test_history.html")) | 566 RunExtensionSubtest("webnavigation", "test_history.html")) |
| 320 << message_; | 567 << message_; |
| 321 } | 568 } |
| 322 | 569 |
| 570 IN_PROC_BROWSER_TEST_F(WebNavigationApiTest, CrossProcess) { | |
| 571 LoadExtension(test_data_dir_.AppendASCII("webnavigation").AppendASCII("app")); | |
| 572 LoadExtension(test_data_dir_.AppendASCII("webnavigation")); | |
| 573 | |
| 574 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 575 const extensions::Extension* extension = | |
| 576 service->GetExtensionById(last_loaded_extension_id_, false); | |
| 577 | |
| 578 // See crossProcess/d.html. | |
| 579 DelayLoadStartAndExecuteJavascript call_script( | |
| 580 test_navigation_listener(), | |
| 581 test_server()->GetURL("test1"), | |
| 582 "navigate2()", | |
| 583 extension->GetResourceURL("crossProcess/empty.html")); | |
| 584 | |
| 585 // See crossProcess/e.html. | |
| 586 DelayLoadStartAndExecuteJavascript call_script2( | |
| 587 test_navigation_listener(), | |
| 588 test_server()->GetURL("test2"), | |
| 589 "updateHistory()", | |
| 590 extension->GetResourceURL("crossProcess/empty.html")); | |
| 591 | |
| 592 // See crossProcess/f.html. | |
| 593 DelayLoadStartAndExecuteJavascript call_script3( | |
| 594 test_navigation_listener(), | |
| 595 test_server()->GetURL("test3"), | |
| 596 "updateFragment()", | |
| 597 extension->GetResourceURL(base::StringPrintf( | |
| 598 "crossProcess/f.html?%d#foo", | |
| 599 test_server()->host_port_pair().port()))); | |
| 600 | |
| 601 // See crossProcess/g.html. | |
| 602 DelayLoadStartAndExecuteJavascript call_script4( | |
| 603 test_navigation_listener(), | |
| 604 test_server()->GetURL("test4"), | |
| 605 "updateFragment()", | |
| 606 extension->GetResourceURL(base::StringPrintf( | |
| 607 "crossProcess/g.html?%d#foo", | |
| 608 test_server()->host_port_pair().port()))); | |
| 609 | |
| 610 // See crossProcess/h.html. | |
| 611 DelayLoadStartAndExecuteJavascript call_script5( | |
| 612 test_navigation_listener(), | |
| 613 test_server()->GetURL("test5"), | |
| 614 "updateHistory()", | |
| 615 extension->GetResourceURL("crossProcess/empty.html")); | |
| 616 | |
| 617 // See crossProcess/i.html. | |
| 618 DelayLoadStartAndExecuteJavascript call_script6( | |
| 619 test_navigation_listener(), | |
| 620 test_server()->GetURL("test6"), | |
| 621 "updateHistory()", | |
| 622 extension->GetResourceURL("crossProcess/empty.html")); | |
| 623 | |
| 624 ASSERT_TRUE(RunPageTest( | |
| 625 extension->GetResourceURL("test_crossProcess.html").spec())) | |
| 626 << message_; | |
| 627 } | |
| 628 | |
| 323 } // namespace extensions | 629 } // namespace extensions |
| OLD | NEW |