| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/automation/automation_util.h" | 10 #include "chrome/browser/automation/automation_util.h" |
| 11 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 11 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 12 #include "chrome/browser/extensions/app_restore_service_factory.h" | 12 #include "chrome/browser/extensions/app_restore_service_factory.h" |
| 13 #include "chrome/browser/extensions/app_restore_service.h" | 13 #include "chrome/browser/extensions/app_restore_service.h" |
| 14 #include "chrome/browser/extensions/extension_browsertest.h" | 14 #include "chrome/browser/extensions/extension_browsertest.h" |
| 15 #include "chrome/browser/extensions/extension_prefs.h" | 15 #include "chrome/browser/extensions/extension_prefs.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/extensions/extension_system.h" | 17 #include "chrome/browser/extensions/extension_system.h" |
| 18 #include "chrome/browser/extensions/extension_test_message_listener.h" | 18 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 19 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 19 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 20 #include "chrome/browser/extensions/platform_app_launcher.h" | 20 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 21 #include "chrome/browser/extensions/shell_window_registry.h" | 21 #include "chrome/browser/extensions/shell_window_registry.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_tabstrip.h" | 23 #include "chrome/browser/ui/browser_tabstrip.h" |
| 24 #include "chrome/browser/ui/extensions/application_launch.h" | 24 #include "chrome/browser/ui/extensions/application_launch.h" |
| 25 #include "chrome/browser/ui/extensions/shell_window.h" | 25 #include "chrome/browser/ui/extensions/shell_window.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
| 27 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/browser/web_intents_dispatcher.h" | 30 #include "content/public/browser/web_intents_dispatcher.h" |
| 30 #include "content/public/test/test_utils.h" | 31 #include "content/public/test/test_utils.h" |
| 31 #include "googleurl/src/gurl.h" | 32 #include "googleurl/src/gurl.h" |
| 32 #include "webkit/glue/web_intent_data.h" | 33 #include "webkit/glue/web_intent_data.h" |
| 33 | 34 |
| 34 using content::WebContents; | 35 using content::WebContents; |
| 35 | 36 |
| 36 namespace extensions { | 37 namespace extensions { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 MessageLoopForUI::current()->Quit(); | 99 MessageLoopForUI::current()->Quit(); |
| 99 } | 100 } |
| 100 | 101 |
| 101 webkit_glue::WebIntentData data_; | 102 webkit_glue::WebIntentData data_; |
| 102 bool replied_; | 103 bool replied_; |
| 103 bool waiting_; | 104 bool waiting_; |
| 104 content::WebIntentsDispatcher* intents_dispatcher_; | 105 content::WebIntentsDispatcher* intents_dispatcher_; |
| 105 base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_; | 106 base::WeakPtrFactory<LaunchReplyHandler> weak_ptr_factory_; |
| 106 }; | 107 }; |
| 107 | 108 |
| 109 // This class keeps track of tabs as they are added to the browser. It will be |
| 110 // "done" (i.e. won't block on Wait()) once |observations| tabs have been added. |
| 111 class TabsAddedNotificationObserver |
| 112 : public content::WindowedNotificationObserver { |
| 113 public: |
| 114 explicit TabsAddedNotificationObserver(size_t observations) |
| 115 : content::WindowedNotificationObserver( |
| 116 chrome::NOTIFICATION_TAB_ADDED, |
| 117 content::NotificationService::AllSources()), |
| 118 observations_(observations) { |
| 119 } |
| 120 |
| 121 virtual void Observe(int type, |
| 122 const content::NotificationSource& source, |
| 123 const content::NotificationDetails& details) OVERRIDE { |
| 124 observed_tabs_.push_back( |
| 125 content::Details<WebContents>(details).ptr()); |
| 126 if (observed_tabs_.size() == observations_) |
| 127 content::WindowedNotificationObserver::Observe(type, source, details); |
| 128 } |
| 129 |
| 130 const std::vector<content::WebContents*>& tabs() { return observed_tabs_; } |
| 131 |
| 132 private: |
| 133 size_t observations_; |
| 134 std::vector<content::WebContents*> observed_tabs_; |
| 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(TabsAddedNotificationObserver); |
| 137 }; |
| 138 |
| 108 const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; | 139 const char kTestFilePath[] = "platform_apps/launch_files/test.txt"; |
| 109 | 140 |
| 110 } // namespace | 141 } // namespace |
| 111 | 142 |
| 112 // Tests that CreateShellWindow doesn't crash if you close it straight away. | 143 // Tests that CreateShellWindow doesn't crash if you close it straight away. |
| 113 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for | 144 // LauncherPlatformAppBrowserTest relies on this behaviour, but is only run for |
| 114 // ash, so we test that it works here. | 145 // ash, so we test that it works here. |
| 115 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { | 146 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, CreateAndCloseShellWindow) { |
| 116 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); | 147 const Extension* extension = LoadAndLaunchPlatformApp("minimal"); |
| 117 ShellWindow* window = CreateShellWindow(extension); | 148 ShellWindow* window = CreateShellWindow(extension); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 348 |
| 318 // Execute the menu item | 349 // Execute the menu item |
| 319 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", | 350 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
| 320 false); | 351 false); |
| 321 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); | 352 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST); |
| 322 | 353 |
| 323 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); | 354 ASSERT_TRUE(onclicked_listener.WaitUntilSatisfied()); |
| 324 } | 355 } |
| 325 | 356 |
| 326 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { | 357 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { |
| 358 TabsAddedNotificationObserver observer(2); |
| 359 |
| 327 ASSERT_TRUE(StartTestServer()); | 360 ASSERT_TRUE(StartTestServer()); |
| 328 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; | 361 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; |
| 362 |
| 363 observer.Wait(); |
| 364 ASSERT_EQ(2U, observer.tabs().size()); |
| 365 EXPECT_EQ(std::string(chrome::kExtensionInvalidRequestURL), |
| 366 observer.tabs()[0]->GetURL().spec()); |
| 367 EXPECT_EQ("http://chromium.org/", |
| 368 observer.tabs()[1]->GetURL().spec()); |
| 329 } | 369 } |
| 330 | 370 |
| 331 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { | 371 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Iframes) { |
| 332 ASSERT_TRUE(StartTestServer()); | 372 ASSERT_TRUE(StartTestServer()); |
| 333 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; | 373 ASSERT_TRUE(RunPlatformAppTest("platform_apps/iframes")) << message_; |
| 334 } | 374 } |
| 335 | 375 |
| 336 // Tests that localStorage and WebSQL are disabled for platform apps. | 376 // Tests that localStorage and WebSQL are disabled for platform apps. |
| 337 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { | 377 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { |
| 338 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; | 378 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 676 |
| 637 // Pretend that the app is supposed to be running. | 677 // Pretend that the app is supposed to be running. |
| 638 extension_prefs->SetExtensionRunning(extension->id(), true); | 678 extension_prefs->SetExtensionRunning(extension->id(), true); |
| 639 | 679 |
| 640 ExtensionTestMessageListener restart_listener("onRestarted", false); | 680 ExtensionTestMessageListener restart_listener("onRestarted", false); |
| 641 AppRestoreServiceFactory::GetForProfile(browser()->profile())->RestoreApps(); | 681 AppRestoreServiceFactory::GetForProfile(browser()->profile())->RestoreApps(); |
| 642 restart_listener.WaitUntilSatisfied(); | 682 restart_listener.WaitUntilSatisfied(); |
| 643 } | 683 } |
| 644 | 684 |
| 645 } // namespace extensions | 685 } // namespace extensions |
| OLD | NEW |