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" |
48 #include "url/gurl.h" | 50 #include "url/gurl.h" |
49 | 51 |
50 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
51 #include "base/memory/scoped_ptr.h" | 53 #include "base/memory/scoped_ptr.h" |
52 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 54 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
53 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 55 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
54 #include "chromeos/dbus/dbus_thread_manager.h" | 56 #include "chromeos/dbus/dbus_thread_manager.h" |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 relative_test_doc = relative_test_doc.NormalizePathSeparators(); | 503 relative_test_doc = relative_test_doc.NormalizePathSeparators(); |
502 command_line->AppendArgPath(relative_test_doc); | 504 command_line->AppendArgPath(relative_test_doc); |
503 | 505 |
504 // Load the extension | 506 // Load the extension |
505 ResultCatcher catcher; | 507 ResultCatcher catcher; |
506 const Extension* extension = LoadExtension( | 508 const Extension* extension = LoadExtension( |
507 test_data_dir_.AppendASCII("platform_apps/launch_file")); | 509 test_data_dir_.AppendASCII("platform_apps/launch_file")); |
508 ASSERT_TRUE(extension); | 510 ASSERT_TRUE(extension); |
509 | 511 |
510 // Run the test | 512 // Run the test |
511 AppLaunchParams params( | 513 AppLaunchParams params(browser()->profile(), extension, LAUNCH_CONTAINER_NONE, |
512 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW); | 514 NEW_WINDOW, extensions::SOURCE_UNTRACKED); |
513 params.command_line = *CommandLine::ForCurrentProcess(); | 515 params.command_line = *CommandLine::ForCurrentProcess(); |
514 params.current_directory = test_data_dir_; | 516 params.current_directory = test_data_dir_; |
515 OpenApplication(params); | 517 OpenApplication(params); |
516 | 518 |
517 if (!catcher.GetNextResult()) { | 519 if (!catcher.GetNextResult()) { |
518 message_ = catcher.message(); | 520 message_ = catcher.message(); |
519 ASSERT_TRUE(0); | 521 ASSERT_TRUE(0); |
520 } | 522 } |
521 } | 523 } |
522 | 524 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 | 833 |
832 if (test_flags & RELAUNCH) { | 834 if (test_flags & RELAUNCH) { |
833 // Close the AppWindow, and ensure it is gone. | 835 // Close the AppWindow, and ensure it is gone. |
834 CloseAppWindow(window); | 836 CloseAppWindow(window); |
835 ASSERT_FALSE(GetFirstAppWindow()); | 837 ASSERT_FALSE(GetFirstAppWindow()); |
836 | 838 |
837 // Relaunch the app and get a new AppWindow. | 839 // Relaunch the app and get a new AppWindow. |
838 content::WindowedNotificationObserver app_loaded_observer( | 840 content::WindowedNotificationObserver app_loaded_observer( |
839 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 841 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
840 content::NotificationService::AllSources()); | 842 content::NotificationService::AllSources()); |
841 OpenApplication(AppLaunchParams( | 843 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
842 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 844 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 845 extensions::SOURCE_UNTRACKED)); |
843 app_loaded_observer.Wait(); | 846 app_loaded_observer.Wait(); |
844 window = GetFirstAppWindow(); | 847 window = GetFirstAppWindow(); |
845 ASSERT_TRUE(window); | 848 ASSERT_TRUE(window); |
846 | 849 |
847 // DevTools should have reopened with the relaunch. | 850 // DevTools should have reopened with the relaunch. |
848 web_contents = window->web_contents(); | 851 web_contents = window->web_contents(); |
849 ASSERT_TRUE(web_contents); | 852 ASSERT_TRUE(web_contents); |
850 ASSERT_TRUE(DevToolsAgentHost::HasFor(web_contents)); | 853 ASSERT_TRUE(DevToolsAgentHost::HasFor(web_contents)); |
851 } | 854 } |
852 } | 855 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 content::NotificationService::AllSources()); | 979 content::NotificationService::AllSources()); |
977 | 980 |
978 const Extension* extension = LoadExtensionAsComponent( | 981 const Extension* extension = LoadExtensionAsComponent( |
979 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 982 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
980 ASSERT_TRUE(extension); | 983 ASSERT_TRUE(extension); |
981 | 984 |
982 app_loaded_observer.Wait(); | 985 app_loaded_observer.Wait(); |
983 ASSERT_TRUE(should_install.seen()); | 986 ASSERT_TRUE(should_install.seen()); |
984 | 987 |
985 ExtensionTestMessageListener launched_listener("Launched", false); | 988 ExtensionTestMessageListener launched_listener("Launched", false); |
986 OpenApplication(AppLaunchParams( | 989 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
987 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 990 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 991 extensions::SOURCE_UNTRACKED)); |
988 | 992 |
989 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 993 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
990 } | 994 } |
991 | 995 |
992 // Component App Test 2 of 3: ensure an installed component app can be launched | 996 // 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 | 997 // on a subsequent browser start, without requiring any install/upgrade logic |
994 // to be run, then perform setup for step 3. | 998 // to be run, then perform setup for step 3. |
995 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 999 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
996 PRE_ComponentAppBackgroundPage) { | 1000 PRE_ComponentAppBackgroundPage) { |
997 | 1001 |
998 // Since the component app is now installed, re-adding it in the same profile | 1002 // 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 | 1003 // 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 | 1004 // 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 | 1005 // previously installed properly) and then check this observer to make sure it |
1002 // never saw the NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED event. | 1006 // never saw the NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED event. |
1003 CheckExtensionInstalledObserver should_not_install; | 1007 CheckExtensionInstalledObserver should_not_install; |
1004 const Extension* extension = LoadExtensionAsComponent( | 1008 const Extension* extension = LoadExtensionAsComponent( |
1005 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 1009 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
1006 ASSERT_TRUE(extension); | 1010 ASSERT_TRUE(extension); |
1007 | 1011 |
1008 ExtensionTestMessageListener launched_listener("Launched", false); | 1012 ExtensionTestMessageListener launched_listener("Launched", false); |
1009 OpenApplication(AppLaunchParams( | 1013 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
1010 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 1014 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 1015 extensions::SOURCE_UNTRACKED)); |
1011 | 1016 |
1012 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 1017 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
1013 ASSERT_FALSE(should_not_install.seen()); | 1018 ASSERT_FALSE(should_not_install.seen()); |
1014 | 1019 |
1015 // Simulate a "downgrade" from version 2 in the test manifest.json to 1. | 1020 // Simulate a "downgrade" from version 2 in the test manifest.json to 1. |
1016 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser()->profile()); | 1021 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(browser()->profile()); |
1017 | 1022 |
1018 // Clear the registered events to ensure they are updated. | 1023 // Clear the registered events to ensure they are updated. |
1019 extensions::EventRouter::Get(browser()->profile()) | 1024 extensions::EventRouter::Get(browser()->profile()) |
1020 ->SetRegisteredEvents(extension->id(), std::set<std::string>()); | 1025 ->SetRegisteredEvents(extension->id(), std::set<std::string>()); |
(...skipping 15 matching lines...) Expand all Loading... |
1036 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1041 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
1037 content::NotificationService::AllSources()); | 1042 content::NotificationService::AllSources()); |
1038 | 1043 |
1039 const Extension* extension = LoadExtensionAsComponent( | 1044 const Extension* extension = LoadExtensionAsComponent( |
1040 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 1045 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
1041 ASSERT_TRUE(extension); | 1046 ASSERT_TRUE(extension); |
1042 app_loaded_observer.Wait(); | 1047 app_loaded_observer.Wait(); |
1043 ASSERT_TRUE(should_install.seen()); | 1048 ASSERT_TRUE(should_install.seen()); |
1044 | 1049 |
1045 ExtensionTestMessageListener launched_listener("Launched", false); | 1050 ExtensionTestMessageListener launched_listener("Launched", false); |
1046 OpenApplication(AppLaunchParams( | 1051 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
1047 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 1052 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 1053 extensions::SOURCE_UNTRACKED)); |
1048 | 1054 |
1049 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 1055 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
1050 } | 1056 } |
1051 | 1057 |
1052 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, | 1058 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, |
1053 ComponentExtensionRuntimeReload) { | 1059 ComponentExtensionRuntimeReload) { |
1054 // Ensure that we wait until the background page is run (to register the | 1060 // 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 | 1061 // OnLaunched listener) before trying to open the application. This is similar |
1056 // to LoadAndLaunchPlatformApp, but we want to load as a component extension. | 1062 // to LoadAndLaunchPlatformApp, but we want to load as a component extension. |
1057 content::WindowedNotificationObserver app_loaded_observer( | 1063 content::WindowedNotificationObserver app_loaded_observer( |
1058 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 1064 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
1059 content::NotificationService::AllSources()); | 1065 content::NotificationService::AllSources()); |
1060 | 1066 |
1061 const Extension* extension = LoadExtensionAsComponent( | 1067 const Extension* extension = LoadExtensionAsComponent( |
1062 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); | 1068 test_data_dir_.AppendASCII("platform_apps").AppendASCII("component")); |
1063 ASSERT_TRUE(extension); | 1069 ASSERT_TRUE(extension); |
1064 | 1070 |
1065 app_loaded_observer.Wait(); | 1071 app_loaded_observer.Wait(); |
1066 | 1072 |
1067 { | 1073 { |
1068 ExtensionTestMessageListener launched_listener("Launched", false); | 1074 ExtensionTestMessageListener launched_listener("Launched", false); |
1069 OpenApplication(AppLaunchParams( | 1075 OpenApplication(AppLaunchParams(browser()->profile(), extension, |
1070 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 1076 LAUNCH_CONTAINER_NONE, NEW_WINDOW, |
| 1077 extensions::SOURCE_UNTRACKED)); |
1071 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 1078 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
1072 } | 1079 } |
1073 | 1080 |
1074 { | 1081 { |
1075 ExtensionTestMessageListener launched_listener("Launched", false); | 1082 ExtensionTestMessageListener launched_listener("Launched", false); |
1076 ASSERT_TRUE(ExecuteScriptInBackgroundPageNoWait( | 1083 ASSERT_TRUE(ExecuteScriptInBackgroundPageNoWait( |
1077 extension->id(), | 1084 extension->id(), |
1078 // NoWait actually waits for a domAutomationController.send() which is | 1085 // NoWait actually waits for a domAutomationController.send() which is |
1079 // implicitly append to the script. Since reload() restarts the | 1086 // implicitly append to the script. Since reload() restarts the |
1080 // extension, the send after reload may not get executed. To get around | 1087 // 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( | 1217 while (!router->ExtensionHasEventListener( |
1211 file_manager->id(), app_runtime::OnLaunched::kEventName)) { | 1218 file_manager->id(), app_runtime::OnLaunched::kEventName)) { |
1212 content::RunAllPendingInMessageLoop(); | 1219 content::RunAllPendingInMessageLoop(); |
1213 } | 1220 } |
1214 | 1221 |
1215 // Listen for new app windows so we see the file manager app launch itself. | 1222 // Listen for new app windows so we see the file manager app launch itself. |
1216 AppWindowRegistry* registry = AppWindowRegistry::Get(incognito_profile); | 1223 AppWindowRegistry* registry = AppWindowRegistry::Get(incognito_profile); |
1217 ASSERT_TRUE(registry != NULL); | 1224 ASSERT_TRUE(registry != NULL); |
1218 registry->AddObserver(this); | 1225 registry->AddObserver(this); |
1219 | 1226 |
1220 OpenApplication(AppLaunchParams( | 1227 OpenApplication(AppLaunchParams(incognito_profile, file_manager, 0, |
1221 incognito_profile, file_manager, 0, chrome::HOST_DESKTOP_TYPE_NATIVE)); | 1228 chrome::HOST_DESKTOP_TYPE_NATIVE, |
| 1229 extensions::SOURCE_UNTRACKED)); |
1222 | 1230 |
1223 while (!ContainsKey(opener_app_ids_, file_manager->id())) { | 1231 while (!ContainsKey(opener_app_ids_, file_manager->id())) { |
1224 content::RunAllPendingInMessageLoop(); | 1232 content::RunAllPendingInMessageLoop(); |
1225 } | 1233 } |
1226 } | 1234 } |
1227 | 1235 |
1228 class RestartDeviceTest : public PlatformAppBrowserTest { | 1236 class RestartDeviceTest : public PlatformAppBrowserTest { |
1229 public: | 1237 public: |
1230 RestartDeviceTest() | 1238 RestartDeviceTest() |
1231 : power_manager_client_(NULL), | 1239 : power_manager_client_(NULL), |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 LoadAndLaunchPlatformApp("reinstall_data_cleanup", "Launched"); | 1330 LoadAndLaunchPlatformApp("reinstall_data_cleanup", "Launched"); |
1323 ASSERT_TRUE(extension); | 1331 ASSERT_TRUE(extension); |
1324 ASSERT_EQ(extension_id, extension->id()); | 1332 ASSERT_EQ(extension_id, extension->id()); |
1325 | 1333 |
1326 ResultCatcher result_catcher; | 1334 ResultCatcher result_catcher; |
1327 EXPECT_TRUE(result_catcher.GetNextResult()); | 1335 EXPECT_TRUE(result_catcher.GetNextResult()); |
1328 } | 1336 } |
1329 } | 1337 } |
1330 | 1338 |
1331 } // namespace extensions | 1339 } // namespace extensions |
OLD | NEW |