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

Side by Side Diff: chrome/browser/extensions/platform_app_browsertest.cc

Issue 10080017: Switch platform apps from a declarative launch container to handling an onLaunched event. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: remove debug logging code Created 8 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/stringprintf.h" 6 #include "base/stringprintf.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/extensions/extension_browsertest.h" 9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_host.h" 10 #include "chrome/browser/extensions/extension_host.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_test_message_listener.h" 12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/tab_contents/render_view_context_menu.h" 14 #include "chrome/browser/tab_contents/render_view_context_menu.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/chrome_view_type.h"
18 #include "chrome/common/extensions/extension_constants.h" 19 #include "chrome/common/extensions/extension_constants.h"
19 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/context_menu_params.h" 22 #include "content/public/common/context_menu_params.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #include "ui/base/models/menu_model.h" 24 #include "ui/base/models/menu_model.h"
24 25
25 using content::WebContents; 26 using content::WebContents;
26 27
27 namespace { 28 namespace {
(...skipping 14 matching lines...) Expand all
42 virtual void PlatformInit() {} 43 virtual void PlatformInit() {}
43 }; 44 };
44 45
45 } // namespace 46 } // namespace
46 47
47 class PlatformAppBrowserTest : public ExtensionApiTest { 48 class PlatformAppBrowserTest : public ExtensionApiTest {
48 public: 49 public:
49 virtual void SetUpCommandLine(CommandLine* command_line) { 50 virtual void SetUpCommandLine(CommandLine* command_line) {
50 ExtensionBrowserTest::SetUpCommandLine(command_line); 51 ExtensionBrowserTest::SetUpCommandLine(command_line);
51 command_line->AppendSwitch(switches::kEnablePlatformApps); 52 command_line->AppendSwitch(switches::kEnablePlatformApps);
53 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
52 } 54 }
53 55
54 protected: 56 protected:
55 void LoadAndLaunchPlatformApp(const char* name) { 57 void LoadAndLaunchPlatformApp(const char* name) {
58 size_t platform_app_count = GetPlatformAppCount();
56 ui_test_utils::WindowedNotificationObserver app_loaded_observer( 59 ui_test_utils::WindowedNotificationObserver app_loaded_observer(
57 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 60 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
58 content::NotificationService::AllSources()); 61 content::NotificationService::AllSources());
59 62
60 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps"). 63 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps").
61 AppendASCII(name))); 64 AppendASCII(name)));
62 65
63 ExtensionService* service = browser()->profile()->GetExtensionService(); 66 ExtensionService* service = browser()->profile()->GetExtensionService();
64 const Extension* extension = service->GetExtensionById( 67 const Extension* extension = service->GetExtensionById(
65 last_loaded_extension_id_, false); 68 last_loaded_extension_id_, false);
66 EXPECT_TRUE(extension); 69 EXPECT_TRUE(extension);
67 70
68 size_t platform_app_count = GetPlatformAppCount();
69
70 Browser::OpenApplication( 71 Browser::OpenApplication(
71 browser()->profile(), 72 browser()->profile(),
72 extension, 73 extension,
73 extension_misc::LAUNCH_SHELL, 74 extension_misc::LAUNCH_NONE,
74 GURL(), 75 GURL(),
75 NEW_WINDOW); 76 NEW_WINDOW);
76 77
77 app_loaded_observer.Wait(); 78 app_loaded_observer.Wait();
78 79
79 // Now we have a new platform app running. 80 // Now we have a new platform app running.
80 EXPECT_EQ(platform_app_count + 1, GetPlatformAppCount()); 81 EXPECT_EQ(platform_app_count + 1, GetPlatformAppCount());
81 } 82 }
82 83
83 // Gets the number of platform apps that are running. 84 // Gets the number of platform apps extension hosts that are running.
84 size_t GetPlatformAppCount() { 85 size_t GetPlatformAppCount() {
85 int count = 0; 86 int count = 0;
86 ExtensionProcessManager* process_manager = 87 ExtensionProcessManager* process_manager =
87 browser()->profile()->GetExtensionProcessManager(); 88 browser()->profile()->GetExtensionProcessManager();
88 ExtensionProcessManager::const_iterator iter; 89 ExtensionProcessManager::const_iterator iter;
89 for (iter = process_manager->begin(); iter != process_manager->end(); 90 for (iter = process_manager->begin(); iter != process_manager->end();
90 ++iter) { 91 ++iter) {
91 ExtensionHost* host = *iter; 92 ExtensionHost* host = *iter;
92 if (host->extension() && host->extension()->is_platform_app()) 93 if (host->extension() && host->extension()->is_platform_app())
93 count++; 94 count++;
94 } 95 }
95 96
96 return count; 97 return count;
97 } 98 }
98 99
99 // Gets the WebContents associated with the ExtensionHost of the first 100 // Gets the WebContents associated with the ExtensionHost of the first
100 // platform app that is found (most tests only deal with one platform 101 // platform app shell window that is found (most tests only deal with one
101 // app, so this is good enough). 102 // platform app window, so this is good enough).
102 WebContents* GetFirstPlatformAppWebContents() { 103 WebContents* GetFirstPlatformAppShellWindowWebContents() {
103 ExtensionProcessManager* process_manager = 104 ExtensionProcessManager* process_manager =
104 browser()->profile()->GetExtensionProcessManager(); 105 browser()->profile()->GetExtensionProcessManager();
105 ExtensionProcessManager::const_iterator iter; 106 ExtensionProcessManager::const_iterator iter;
106 for (iter = process_manager->begin(); iter != process_manager->end(); 107 for (iter = process_manager->begin(); iter != process_manager->end();
107 ++iter) { 108 ++iter) {
108 ExtensionHost* host = *iter; 109 ExtensionHost* host = *iter;
109 if (host->extension() && host->extension()->is_platform_app()) 110 if (host->extension() && host->extension()->is_platform_app() &&
111 host->extension_host_type() == chrome::VIEW_TYPE_APP_SHELL)
110 return host->host_contents(); 112 return host->host_contents();
111 } 113 }
112 114
113 return NULL; 115 return NULL;
114 } 116 }
115 }; 117 };
116 118
117 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OpenAppInShellContainer) { 119 // Tests that platform apps received the "launch" event when launched.
118 ASSERT_EQ(0u, GetPlatformAppCount()); 120 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
119 LoadAndLaunchPlatformApp("empty"); 121 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
120 ASSERT_EQ(1u, GetPlatformAppCount());
121
122 UnloadExtension(last_loaded_extension_id_);
123 ASSERT_EQ(0u, GetPlatformAppCount());
124 } 122 }
125 123
126 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 124 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
127 LoadAndLaunchPlatformApp("empty"); 125 ExtensionTestMessageListener launched_listener("Launched", false);
126 LoadAndLaunchPlatformApp("empty_context_menu");
127
128 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
128 129
129 // The empty app doesn't add any context menu items, so its menu should 130 // The empty app doesn't add any context menu items, so its menu should
130 // only include the developer tools. 131 // only include the developer tools.
131 WebContents* web_contents = GetFirstPlatformAppWebContents(); 132 WebContents* web_contents = GetFirstPlatformAppShellWindowWebContents();
132 ASSERT_TRUE(web_contents); 133 ASSERT_TRUE(web_contents);
133 WebKit::WebContextMenuData data; 134 WebKit::WebContextMenuData data;
134 content::ContextMenuParams params(data); 135 content::ContextMenuParams params(data);
135 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 136 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
136 params); 137 params);
137 menu->Init(); 138 menu->Init();
138 // 3 including separator 139 // 3 including separator
139 ASSERT_EQ(3, menu->menu_model().GetItemCount()); 140 ASSERT_EQ(3, menu->menu_model().GetItemCount());
140 } 141 }
141 142
142 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { 143 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
143 ExtensionTestMessageListener listener1("created item", false); 144 ExtensionTestMessageListener launched_listener("Launched", false);
144 LoadAndLaunchPlatformApp("context_menu"); 145 LoadAndLaunchPlatformApp("context_menu");
145 146
146 // Wait for the extension to tell us it's created an item. 147 // Wait for the extension to tell us it's initialized its context menus and
147 ASSERT_TRUE(listener1.WaitUntilSatisfied()); 148 // launched a window.
149 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
148 150
149 // The context_menu app has one context menu item. This, along with a 151 // The context_menu app has one context menu item. This, along with a
150 // separator and the developer tools, is all that should be in the menu. 152 // separator and the developer tools, is all that should be in the menu.
151 WebContents* web_contents = GetFirstPlatformAppWebContents(); 153 WebContents* web_contents = GetFirstPlatformAppShellWindowWebContents();
152 ASSERT_TRUE(web_contents); 154 ASSERT_TRUE(web_contents);
153 WebKit::WebContextMenuData data; 155 WebKit::WebContextMenuData data;
154 content::ContextMenuParams params(data); 156 content::ContextMenuParams params(data);
155 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 157 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
156 params); 158 params);
157 menu->Init(); 159 menu->Init();
158 ASSERT_EQ(4, menu->menu_model().GetItemCount()); 160 ASSERT_EQ(4, menu->menu_model().GetItemCount());
159 } 161 }
160 162
161 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { 163 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) {
162 ASSERT_TRUE(test_server()->Start()); 164 ASSERT_TRUE(StartTestServer());
163 165 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_;
164 LoadAndLaunchPlatformApp("navigation");
165 WebContents* web_contents = GetFirstPlatformAppWebContents();
166
167 GURL remote_url = test_server()->GetURL(
168 "files/extensions/platform_apps/navigation/nav-target.html");
169
170 std::string script = StringPrintf(
171 "runTests(\"%s\")", remote_url.spec().c_str());
172 bool result = false;
173 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
174 web_contents->GetRenderViewHost(), L"",
175 UTF8ToWide(script), &result));
176 EXPECT_TRUE(result);
177 } 166 }
178 167
179 // Tests that localStorage and WebSQL are disabled for platform apps. 168 // Tests that localStorage and WebSQL are disabled for platform apps.
180 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { 169 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) {
181 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_; 170 ASSERT_TRUE(RunPlatformAppTest("platform_apps/storage")) << message_;
182 } 171 }
183 172
184 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) { 173 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, Restrictions) {
185 ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_; 174 ASSERT_TRUE(RunPlatformAppTest("platform_apps/restrictions")) << message_;
186 } 175 }
187 176
188 // Tests that platform apps can use the chrome.windows.* API. 177 // Tests that platform apps can use the chrome.windows.* API.
189 #if defined(USE_AURA) 178 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, WindowsApi) {
190 // On Aura, this currently fails because the window width is returned as 256
191 // instead of 250. See http://crbug.com/119410.
192 #define MAYBE_WindowsApi FAILS_WindowsApi
193 #else
194 #define MAYBE_WindowsApi WindowsApi
195 #endif
196 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_WindowsApi) {
197 ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_; 179 ASSERT_TRUE(RunPlatformAppTest("platform_apps/windows_api")) << message_;
198 } 180 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_tabs_module.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698