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 "base/utf_string_conversions.h" | |
| 6 #include "base/stringprintf.h" | |
| 5 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 6 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" | 8 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 12 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 11 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_tabstrip.h" | 14 #include "chrome/browser/ui/browser_tabstrip.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | |
| 13 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/context_menu_params.h" | 20 #include "content/public/common/context_menu_params.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
| 19 #include "net/base/mock_host_resolver.h" | 22 #include "net/base/mock_host_resolver.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 22 | 25 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 37 private: | 40 private: |
| 38 virtual void PlatformInit() {} | 41 virtual void PlatformInit() {} |
| 39 virtual void PlatformCancel() {} | 42 virtual void PlatformCancel() {} |
| 40 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { | 43 virtual bool GetAcceleratorForCommandId(int, ui::Accelerator*) { |
| 41 return false; | 44 return false; |
| 42 } | 45 } |
| 43 | 46 |
| 44 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); | 47 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
| 45 }; | 48 }; |
| 46 | 49 |
| 50 // Waits for a WC to be created and invokes the given JavaScript |method| on | |
| 51 // that WC once it starts loading |url|. | |
| 52 class CallMethodOnLoad : public content::NotificationObserver, | |
| 53 public content::WebContentsObserver { | |
| 54 public: | |
| 55 CallMethodOnLoad(const std::string& method, | |
|
Charlie Reis
2012/08/06 20:04:13
This is really just an arbitrary string to execute
jochen (gone - plz use gerrit)
2012/08/06 21:08:39
Done.
| |
| 56 const GURL& url) | |
| 57 : content::WebContentsObserver(), | |
| 58 method_(method), | |
| 59 url_(url), | |
| 60 rvh_(NULL) { | |
| 61 registrar_.Add(this, | |
| 62 chrome::NOTIFICATION_TAB_ADDED, | |
| 63 content::NotificationService::AllSources()); | |
| 64 } | |
| 65 virtual ~CallMethodOnLoad() {} | |
| 66 | |
| 67 virtual void Observe(int type, | |
| 68 const content::NotificationSource& source, | |
| 69 const content::NotificationDetails& details) OVERRIDE { | |
| 70 if (type != chrome::NOTIFICATION_TAB_ADDED) { | |
| 71 NOTREACHED(); | |
| 72 return; | |
| 73 } | |
| 74 content::WebContentsObserver::Observe( | |
| 75 content::Details<content::WebContents>(details).ptr()); | |
| 76 registrar_.RemoveAll(); | |
| 77 } | |
| 78 | |
| 79 virtual void DidStartProvisionalLoadForFrame( | |
| 80 int64 frame_id, | |
| 81 bool is_main_frame, | |
| 82 const GURL& validated_url, | |
| 83 bool is_error_page, | |
| 84 content::RenderViewHost* render_view_host) OVERRIDE { | |
| 85 if (validated_url != url_ || !rvh_) | |
|
Charlie Reis
2012/08/06 20:04:13
This is an unexpected condition to me. It looks l
jochen (gone - plz use gerrit)
2012/08/06 21:08:39
Done.
| |
| 86 return; | |
| 87 | |
| 88 rvh_->ExecuteJavascriptInWebFrame(string16(), UTF8ToUTF16(method_)); | |
| 89 content::WebContentsObserver::Observe(NULL); | |
| 90 } | |
| 91 | |
| 92 virtual void DidCommitProvisionalLoadForFrame( | |
| 93 int64 frame_id, | |
| 94 bool is_main_frame, | |
| 95 const GURL& url, | |
| 96 content::PageTransition transition_type, | |
| 97 content::RenderViewHost* render_view_host) OVERRIDE { | |
| 98 if (!is_main_frame) | |
| 99 return; | |
| 100 rvh_ = render_view_host; | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 content::NotificationRegistrar registrar_; | |
| 105 | |
| 106 std::string method_; | |
| 107 GURL url_; | |
| 108 content::RenderViewHost* rvh_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(CallMethodOnLoad); | |
| 111 }; | |
| 112 | |
| 47 } // namespace | 113 } // namespace |
| 48 | 114 |
| 49 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigation) { | 115 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigation) { |
| 50 FrameNavigationState::set_allow_extension_scheme(true); | 116 FrameNavigationState::set_allow_extension_scheme(true); |
| 51 | 117 |
| 52 CommandLine::ForCurrentProcess()->AppendSwitch( | 118 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 53 switches::kAllowLegacyExtensionManifests); | 119 switches::kAllowLegacyExtensionManifests); |
| 54 | 120 |
| 55 ASSERT_TRUE( | 121 ASSERT_TRUE( |
| 56 RunExtensionSubtest("webnavigation", "test_api.html")) << message_; | 122 RunExtensionSubtest("webnavigation", "test_api.html")) << message_; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 FrameNavigationState::set_allow_extension_scheme(true); | 379 FrameNavigationState::set_allow_extension_scheme(true); |
| 314 | 380 |
| 315 CommandLine::ForCurrentProcess()->AppendSwitch( | 381 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 316 switches::kAllowLegacyExtensionManifests); | 382 switches::kAllowLegacyExtensionManifests); |
| 317 | 383 |
| 318 ASSERT_TRUE( | 384 ASSERT_TRUE( |
| 319 RunExtensionSubtest("webnavigation", "test_history.html")) | 385 RunExtensionSubtest("webnavigation", "test_history.html")) |
| 320 << message_; | 386 << message_; |
| 321 } | 387 } |
| 322 | 388 |
| 389 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WebNavigationCrossProcess) { | |
| 390 FrameNavigationState::set_allow_extension_scheme(true); | |
| 391 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 392 ASSERT_TRUE(StartTestServer()); | |
| 393 | |
| 394 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 395 switches::kAllowLegacyExtensionManifests); | |
| 396 | |
| 397 LoadExtension(test_data_dir_.AppendASCII("webnavigation").AppendASCII("app")); | |
| 398 | |
| 399 // See crossProcess/d.html. | |
| 400 CallMethodOnLoad call_method("navigate2()", test_server()->GetURL("slow?30")); | |
|
Charlie Reis
2012/08/06 20:04:13
When running this test manually, can you check whe
jochen (gone - plz use gerrit)
2012/08/06 21:08:39
Chrome cancels the request immediately, so the tes
Charlie Reis
2012/08/06 21:30:26
I'd prefer you check with a Chrome trooper about t
jochen (gone - plz use gerrit)
2012/08/06 21:42:32
I talked with Nicolas and he pointed out that whil
| |
| 401 | |
| 402 // See crossProcess/e.html. | |
| 403 CallMethodOnLoad call_method2( | |
| 404 "updateHistory()", test_server()->GetURL("slow?31")); | |
| 405 | |
| 406 // See crossProcess/f.html. | |
| 407 CallMethodOnLoad call_method3( | |
| 408 "updateFragment()", test_server()->GetURL("slow?32")); | |
| 409 | |
| 410 ASSERT_TRUE( | |
| 411 RunExtensionSubtest("webnavigation", "test_crossProcess.html")) | |
| 412 << message_; | |
| 413 } | |
| 414 | |
| 323 } // namespace extensions | 415 } // namespace extensions |
| OLD | NEW |