Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(896)

Side by Side Diff: chrome/browser/apps/app_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698