OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/launcher.h" | 5 #include "apps/launcher.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
14 #include "chrome/browser/apps/app_browsertest_util.h" | 14 #include "chrome/browser/apps/app_browsertest_util.h" |
15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
16 #include "chrome/browser/devtools/devtools_window.h" | 16 #include "chrome/browser/devtools/devtools_window.h" |
17 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | 17 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
18 #include "chrome/browser/extensions/component_loader.h" | 18 #include "chrome/browser/extensions/component_loader.h" |
19 #include "chrome/browser/extensions/extension_browsertest.h" | 19 #include "chrome/browser/extensions/extension_browsertest.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 21 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/extensions/app_launch_params.h" |
23 #include "chrome/browser/ui/extensions/application_launch.h" | 24 #include "chrome/browser/ui/extensions/application_launch.h" |
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
25 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" | 26 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
28 #include "chrome/test/base/test_switches.h" | 29 #include "chrome/test/base/test_switches.h" |
29 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
30 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
31 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 32 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
32 #include "content/public/browser/devtools_agent_host.h" | 33 #include "content/public/browser/devtools_agent_host.h" |
33 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/browser/render_widget_host_view.h" | 35 #include "content/public/browser/render_widget_host_view.h" |
35 #include "content/public/test/test_utils.h" | 36 #include "content/public/test/test_utils.h" |
36 #include "extensions/browser/app_window/app_window.h" | 37 #include "extensions/browser/app_window/app_window.h" |
37 #include "extensions/browser/app_window/app_window_registry.h" | 38 #include "extensions/browser/app_window/app_window_registry.h" |
38 #include "extensions/browser/app_window/native_app_window.h" | 39 #include "extensions/browser/app_window/native_app_window.h" |
39 #include "extensions/browser/event_router.h" | 40 #include "extensions/browser/event_router.h" |
40 #include "extensions/browser/extension_prefs.h" | 41 #include "extensions/browser/extension_prefs.h" |
41 #include "extensions/browser/extension_system.h" | 42 #include "extensions/browser/extension_system.h" |
42 #include "extensions/browser/notification_types.h" | 43 #include "extensions/browser/notification_types.h" |
43 #include "extensions/browser/pref_names.h" | 44 #include "extensions/browser/pref_names.h" |
44 #include "extensions/common/api/app_runtime.h" | 45 #include "extensions/common/api/app_runtime.h" |
| 46 #include "extensions/common/constants.h" |
45 #include "extensions/test/extension_test_message_listener.h" | 47 #include "extensions/test/extension_test_message_listener.h" |
46 #include "extensions/test/result_catcher.h" | 48 #include "extensions/test/result_catcher.h" |
47 #include "net/test/embedded_test_server/embedded_test_server.h" | 49 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 50 #include "ui/base/window_open_disposition.h" |
48 #include "url/gurl.h" | 51 #include "url/gurl.h" |
49 | 52 |
50 #if defined(OS_CHROMEOS) | 53 #if defined(OS_CHROMEOS) |
51 #include "base/memory/scoped_ptr.h" | 54 #include "base/memory/scoped_ptr.h" |
52 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 55 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
53 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 56 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
54 #include "chromeos/dbus/dbus_thread_manager.h" | 57 #include "chromeos/dbus/dbus_thread_manager.h" |
55 #include "chromeos/dbus/fake_power_manager_client.h" | 58 #include "chromeos/dbus/fake_power_manager_client.h" |
56 #endif | 59 #endif |
57 | 60 |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 relative_test_doc = relative_test_doc.NormalizePathSeparators(); | 504 relative_test_doc = relative_test_doc.NormalizePathSeparators(); |
502 command_line->AppendArgPath(relative_test_doc); | 505 command_line->AppendArgPath(relative_test_doc); |
503 | 506 |
504 // Load the extension | 507 // Load the extension |
505 ResultCatcher catcher; | 508 ResultCatcher catcher; |
506 const Extension* extension = LoadExtension( | 509 const Extension* extension = LoadExtension( |
507 test_data_dir_.AppendASCII("platform_apps/launch_file")); | 510 test_data_dir_.AppendASCII("platform_apps/launch_file")); |
508 ASSERT_TRUE(extension); | 511 ASSERT_TRUE(extension); |
509 | 512 |
510 // Run the test | 513 // Run the test |
511 AppLaunchParams params( | 514 AppLaunchParams params(browser()->profile(), extension, LAUNCH_CONTAINER_NONE, |
512 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW); | 515 NEW_WINDOW, extensions::SOURCE_UNTRACKED); |
513 params.command_line = *CommandLine::ForCurrentProcess(); | 516 params.command_line = *CommandLine::ForCurrentProcess(); |
514 params.current_directory = test_data_dir_; | 517 params.current_directory = test_data_dir_; |
515 OpenApplication(params); | 518 OpenApplication(params); |
516 | 519 |
517 if (!catcher.GetNextResult()) { | 520 if (!catcher.GetNextResult()) { |
518 message_ = catcher.message(); | 521 message_ = catcher.message(); |
519 ASSERT_TRUE(0); | 522 ASSERT_TRUE(0); |
520 } | 523 } |
521 } | 524 } |
522 | 525 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 | 834 |
832 if (test_flags & RELAUNCH) { | 835 if (test_flags & RELAUNCH) { |
833 // Close the AppWindow, and ensure it is gone. | 836 // Close the AppWindow, and ensure it is gone. |
834 CloseAppWindow(window); | 837 CloseAppWindow(window); |
835 ASSERT_FALSE(GetFirstAppWindow()); | 838 ASSERT_FALSE(GetFirstAppWindow()); |
836 | 839 |
837 // Relaunch the app and get a new AppWindow. | 840 // Relaunch the app and get a new AppWindow. |
838 content::WindowedNotificationObserver app_loaded_observer( | 841 content::WindowedNotificationObserver app_loaded_observer( |
839 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 842 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
840 content::NotificationService::AllSources()); | 843 content::NotificationService::AllSources()); |
841 OpenApplication(AppLaunchParams( | 844 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
842 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 845 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 846 extensions::SOURCE_UNTRACKED)); |
843 app_loaded_observer.Wait(); | 847 app_loaded_observer.Wait(); |
844 window = GetFirstAppWindow(); | 848 window = GetFirstAppWindow(); |
845 ASSERT_TRUE(window); | 849 ASSERT_TRUE(window); |
846 | 850 |
847 // DevTools should have reopened with the relaunch. | 851 // DevTools should have reopened with the relaunch. |
848 web_contents = window->web_contents(); | 852 web_contents = window->web_contents(); |
849 ASSERT_TRUE(web_contents); | 853 ASSERT_TRUE(web_contents); |
850 ASSERT_TRUE(DevToolsAgentHost::HasFor(web_contents)); | 854 ASSERT_TRUE(DevToolsAgentHost::HasFor(web_contents)); |
851 } | 855 } |
852 } | 856 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 content::NotificationService::AllSources()); | 980 content::NotificationService::AllSources()); |
977 | 981 |
978 const Extension* extension = LoadExtensionAsComponent( | 982 const Extension* extension = LoadExtensionAsComponent( |
979 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 983 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
980 ASSERT_TRUE(extension); | 984 ASSERT_TRUE(extension); |
981 | 985 |
982 app_loaded_observer.Wait(); | 986 app_loaded_observer.Wait(); |
983 ASSERT_TRUE(should_install.seen()); | 987 ASSERT_TRUE(should_install.seen()); |
984 | 988 |
985 ExtensionTestMessageListener launched_listener("Launched", false); | 989 ExtensionTestMessageListener launched_listener("Launched", false); |
986 OpenApplication(AppLaunchParams( | 990 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
987 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 991 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 992 extensions::SOURCE_UNTRACKED)); |
988 | 993 |
989 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 994 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
990 } | 995 } |
991 | 996 |
992 // Component App Test 2 of 3: ensure an installed component app can be launched | 997 // Component App Test 2 of 3: ensure an installed component app can be launched |
993 // on a subsequent browser start, without requiring any install/upgrade logic | 998 // on a subsequent browser start, without requiring any install/upgrade logic |
994 // to be run, then perform setup for step 3. | 999 // to be run, then perform setup for step 3. |
995 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1000 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
996 PRE_ComponentAppBackgroundPage) { | 1001 PRE_ComponentAppBackgroundPage) { |
997 | 1002 |
998 // Since the component app is now installed, re-adding it in the same profile | 1003 // Since the component app is now installed, re-adding it in the same profile |
999 // should not cause it to be re-installed. Instead, we wait for the OnLaunched | 1004 // should not cause it to be re-installed. Instead, we wait for the OnLaunched |
1000 // in a different observer (which would timeout if not the app was not | 1005 // in a different observer (which would timeout if not the app was not |
1001 // previously installed properly) and then check this observer to make sure it | 1006 // previously installed properly) and then check this observer to make sure it |
1002 // never saw the NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED event. | 1007 // never saw the NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED event. |
1003 CheckExtensionInstalledObserver should_not_install; | 1008 CheckExtensionInstalledObserver should_not_install; |
1004 const Extension* extension = LoadExtensionAsComponent( | 1009 const Extension* extension = LoadExtensionAsComponent( |
1005 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 1010 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
1006 ASSERT_TRUE(extension); | 1011 ASSERT_TRUE(extension); |
1007 | 1012 |
1008 ExtensionTestMessageListener launched_listener("Launched", false); | 1013 ExtensionTestMessageListener launched_listener("Launched", false); |
1009 OpenApplication(AppLaunchParams( | 1014 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
1010 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 1015 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 1016 extensions::SOURCE_UNTRACKED)); |
1011 | 1017 |
1012 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 1018 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
1013 ASSERT_FALSE(should_not_install.seen()); | 1019 ASSERT_FALSE(should_not_install.seen()); |
1014 | 1020 |
1015 // Simulate a "downgrade" from version 2 in the test manifest.json to 1. | 1021 // Simulate a "downgrade" from version 2 in the test manifest.json to 1. |
1016 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser()->profile()); | 1022 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser()->profile()); |
1017 | 1023 |
1018 // Clear the registered events to ensure they are updated. | 1024 // Clear the registered events to ensure they are updated. |
1019 extensions::EventRouter::Get(browser()->profile()) | 1025 extensions::EventRouter::Get(browser()->profile()) |
1020 ->SetRegisteredEvents(extension->id(), std::set<std::string>()); | 1026 ->SetRegisteredEvents(extension->id(), std::set<std::string>()); |
(...skipping 15 matching lines...) Expand all Loading... |
1036 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1042 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
1037 content::NotificationService::AllSources()); | 1043 content::NotificationService::AllSources()); |
1038 | 1044 |
1039 const Extension* extension = LoadExtensionAsComponent( | 1045 const Extension* extension = LoadExtensionAsComponent( |
1040 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 1046 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
1041 ASSERT_TRUE(extension); | 1047 ASSERT_TRUE(extension); |
1042 app_loaded_observer.Wait(); | 1048 app_loaded_observer.Wait(); |
1043 ASSERT_TRUE(should_install.seen()); | 1049 ASSERT_TRUE(should_install.seen()); |
1044 | 1050 |
1045 ExtensionTestMessageListener launched_listener("Launched", false); | 1051 ExtensionTestMessageListener launched_listener("Launched", false); |
1046 OpenApplication(AppLaunchParams( | 1052 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
1047 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 1053 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 1054 extensions::SOURCE_UNTRACKED)); |
1048 | 1055 |
1049 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 1056 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
1050 } | 1057 } |
1051 | 1058 |
1052 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1059 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1053 ComponentExtensionRuntimeReload) { | 1060 ComponentExtensionRuntimeReload) { |
1054 // Ensure that we wait until the background page is run (to register the | 1061 // Ensure that we wait until the background page is run (to register the |
1055 // OnLaunched listener) before trying to open the application. This is similar | 1062 // OnLaunched listener) before trying to open the application. This is similar |
1056 // to LoadAndLaunchPlatformApp, but we want to load as a component extension. | 1063 // to LoadAndLaunchPlatformApp, but we want to load as a component extension. |
1057 content::WindowedNotificationObserver app_loaded_observer( | 1064 content::WindowedNotificationObserver app_loaded_observer( |
1058 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1065 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
1059 content::NotificationService::AllSources()); | 1066 content::NotificationService::AllSources()); |
1060 | 1067 |
1061 const Extension* extension = LoadExtensionAsComponent( | 1068 const Extension* extension = LoadExtensionAsComponent( |
1062 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 1069 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
1063 ASSERT_TRUE(extension); | 1070 ASSERT_TRUE(extension); |
1064 | 1071 |
1065 app_loaded_observer.Wait(); | 1072 app_loaded_observer.Wait(); |
1066 | 1073 |
1067 { | 1074 { |
1068 ExtensionTestMessageListener launched_listener("Launched", false); | 1075 ExtensionTestMessageListener launched_listener("Launched", false); |
1069 OpenApplication(AppLaunchParams( | 1076 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
1070 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 1077 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 1078 extensions::SOURCE_UNTRACKED)); |
1071 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 1079 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
1072 } | 1080 } |
1073 | 1081 |
1074 { | 1082 { |
1075 ExtensionTestMessageListener launched_listener("Launched", false); | 1083 ExtensionTestMessageListener launched_listener("Launched", false); |
1076 ASSERT_TRUE(ExecuteScriptInBackgroundPageNoWait( | 1084 ASSERT_TRUE(ExecuteScriptInBackgroundPageNoWait( |
1077 extension->id(), | 1085 extension->id(), |
1078 // NoWait actually waits for a domAutomationController.send() which is | 1086 // NoWait actually waits for a domAutomationController.send() which is |
1079 // implicitly append to the script. Since reload() restarts the | 1087 // implicitly append to the script. Since reload() restarts the |
1080 // extension, the send after reload may not get executed. To get around | 1088 // extension, the send after reload may not get executed. To get around |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 while (!router->ExtensionHasEventListener( | 1218 while (!router->ExtensionHasEventListener( |
1211 file_manager->id(), app_runtime::OnLaunched::kEventName)) { | 1219 file_manager->id(), app_runtime::OnLaunched::kEventName)) { |
1212 content::RunAllPendingInMessageLoop(); | 1220 content::RunAllPendingInMessageLoop(); |
1213 } | 1221 } |
1214 | 1222 |
1215 // Listen for new app windows so we see the file manager app launch itself. | 1223 // Listen for new app windows so we see the file manager app launch itself. |
1216 AppWindowRegistry* registry = AppWindowRegistry::Get(incognito_profile); | 1224 AppWindowRegistry* registry = AppWindowRegistry::Get(incognito_profile); |
1217 ASSERT_TRUE(registry != NULL); | 1225 ASSERT_TRUE(registry != NULL); |
1218 registry->AddObserver(this); | 1226 registry->AddObserver(this); |
1219 | 1227 |
1220 OpenApplication(AppLaunchParams( | 1228 OpenApplication(AppLaunchParams(incognito_profile, file_manager, CURRENT_TAB, |
1221 incognito_profile, file_manager, 0, chrome::HOST_DESKTOP_TYPE_NATIVE)); | 1229 chrome::HOST_DESKTOP_TYPE_NATIVE, |
| 1230 extensions::SOURCE_UNTRACKED)); |
1222 | 1231 |
1223 while (!ContainsKey(opener_app_ids_, file_manager->id())) { | 1232 while (!ContainsKey(opener_app_ids_, file_manager->id())) { |
1224 content::RunAllPendingInMessageLoop(); | 1233 content::RunAllPendingInMessageLoop(); |
1225 } | 1234 } |
1226 } | 1235 } |
1227 | 1236 |
1228 class RestartDeviceTest : public PlatformAppBrowserTest { | 1237 class RestartDeviceTest : public PlatformAppBrowserTest { |
1229 public: | 1238 public: |
1230 RestartDeviceTest() | 1239 RestartDeviceTest() |
1231 : power_manager_client_(NULL), | 1240 : power_manager_client_(NULL), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 LoadAndLaunchPlatformApp("reinstall_data_cleanup", "Launched"); | 1331 LoadAndLaunchPlatformApp("reinstall_data_cleanup", "Launched"); |
1323 ASSERT_TRUE(extension); | 1332 ASSERT_TRUE(extension); |
1324 ASSERT_EQ(extension_id, extension->id()); | 1333 ASSERT_EQ(extension_id, extension->id()); |
1325 | 1334 |
1326 ResultCatcher result_catcher; | 1335 ResultCatcher result_catcher; |
1327 EXPECT_TRUE(result_catcher.GetNextResult()); | 1336 EXPECT_TRUE(result_catcher.GetNextResult()); |
1328 } | 1337 } |
1329 } | 1338 } |
1330 | 1339 |
1331 } // namespace extensions | 1340 } // namespace extensions |
OLD | NEW |