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

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

Issue 10119003: Pull shell window stuff out of ExtensionHost and put in ShellWindow (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comments Created 8 years, 7 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
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/automation/automation_util.h" 8 #include "chrome/browser/automation/automation_util.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 10 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/extensions/extension_host.h"
12 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_test_message_listener.h" 12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/extensions/shell_window_registry.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/tab_contents/render_view_context_menu.h" 15 #include "chrome/browser/tab_contents/render_view_context_menu.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/extensions/shell_window.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/chrome_view_type.h"
20 #include "chrome/common/extensions/extension_constants.h" 20 #include "chrome/common/extensions/extension_constants.h"
21 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/context_menu_params.h" 23 #include "content/public/common/context_menu_params.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/base/models/menu_model.h" 25 #include "ui/base/models/menu_model.h"
26 26
27 using content::WebContents; 27 using content::WebContents;
28 28
29 namespace { 29 namespace {
(...skipping 20 matching lines...) Expand all
50 class PlatformAppBrowserTest : public ExtensionApiTest { 50 class PlatformAppBrowserTest : public ExtensionApiTest {
51 public: 51 public:
52 virtual void SetUpCommandLine(CommandLine* command_line) { 52 virtual void SetUpCommandLine(CommandLine* command_line) {
53 ExtensionBrowserTest::SetUpCommandLine(command_line); 53 ExtensionBrowserTest::SetUpCommandLine(command_line);
54 command_line->AppendSwitch(switches::kEnablePlatformApps); 54 command_line->AppendSwitch(switches::kEnablePlatformApps);
55 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 55 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
56 } 56 }
57 57
58 protected: 58 protected:
59 void LoadAndLaunchPlatformApp(const char* name) { 59 void LoadAndLaunchPlatformApp(const char* name) {
60 size_t platform_app_count = GetPlatformAppCount();
61 ui_test_utils::WindowedNotificationObserver app_loaded_observer( 60 ui_test_utils::WindowedNotificationObserver app_loaded_observer(
62 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, 61 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
63 content::NotificationService::AllSources()); 62 content::NotificationService::AllSources());
64 63
65 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps"). 64 EXPECT_TRUE(LoadExtension(test_data_dir_.AppendASCII("platform_apps").
66 AppendASCII(name))); 65 AppendASCII(name)));
67 66
68 ExtensionService* service = browser()->profile()->GetExtensionService(); 67 ExtensionService* service = browser()->profile()->GetExtensionService();
69 const Extension* extension = service->GetExtensionById( 68 const Extension* extension = service->GetExtensionById(
70 last_loaded_extension_id_, false); 69 last_loaded_extension_id_, false);
71 EXPECT_TRUE(extension); 70 EXPECT_TRUE(extension);
72 71
73 Browser::OpenApplication( 72 Browser::OpenApplication(
74 browser()->profile(), 73 browser()->profile(),
75 extension, 74 extension,
76 extension_misc::LAUNCH_NONE, 75 extension_misc::LAUNCH_NONE,
77 GURL(), 76 GURL(),
78 NEW_WINDOW); 77 NEW_WINDOW);
79 78
80 app_loaded_observer.Wait(); 79 app_loaded_observer.Wait();
81
82 // Now we have a new platform app running.
83 EXPECT_EQ(platform_app_count + 1, GetPlatformAppCount());
84 } 80 }
85 81
86 // Gets the number of platform apps extension hosts that are running. 82 // Gets the WebContents associated with the first shell window that is found
87 size_t GetPlatformAppCount() { 83 // (most tests only deal with one platform app window, so this is good
88 int count = 0; 84 // enough).
89 ExtensionProcessManager* process_manager = 85 WebContents* GetFirstShellWindowWebContents() {
90 browser()->profile()->GetExtensionProcessManager(); 86 ShellWindowRegistry* app_registry =
91 ExtensionProcessManager::const_iterator iter; 87 ShellWindowRegistry::Get(browser()->profile());
92 ExtensionProcessManager::ExtensionHostSet platform_app_hosts = 88 ShellWindowRegistry::const_iterator iter;
93 process_manager->platform_app_hosts(); 89 ShellWindowRegistry::ShellWindowSet shell_windows =
94 for (iter = platform_app_hosts.begin(); iter != platform_app_hosts.end(); 90 app_registry->shell_windows();
95 ++iter) { 91 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) {
96 if ((*iter)->extension()) 92 return (*iter)->web_contents();
97 count++;
98 }
99
100 return count;
101 }
102
103 // Gets the WebContents associated with the ExtensionHost of the first
104 // platform app shell window that is found (most tests only deal with one
105 // platform app window, so this is good enough).
106 WebContents* GetFirstPlatformAppShellWindowWebContents() {
107 ExtensionProcessManager* process_manager =
108 browser()->profile()->GetExtensionProcessManager();
109 ExtensionProcessManager::const_iterator iter;
110 ExtensionProcessManager::ExtensionHostSet platform_app_hosts =
111 process_manager->platform_app_hosts();
112 for (iter = platform_app_hosts.begin(); iter != platform_app_hosts.end();
113 ++iter) {
114 if ((*iter)->extension_host_type() == chrome::VIEW_TYPE_APP_SHELL)
115 return (*iter)->host_contents();
116 } 93 }
117 94
118 return NULL; 95 return NULL;
119 } 96 }
120 }; 97 };
121 98
122 // Tests that platform apps received the "launch" event when launched. 99 // Tests that platform apps received the "launch" event when launched.
123 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) { 100 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, OnLaunchedEvent) {
124 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_; 101 ASSERT_TRUE(RunPlatformAppTest("platform_apps/launch")) << message_;
125 } 102 }
126 103
127 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { 104 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) {
128 ExtensionTestMessageListener launched_listener("Launched", false); 105 ExtensionTestMessageListener launched_listener("Launched", false);
129 LoadAndLaunchPlatformApp("empty_context_menu"); 106 LoadAndLaunchPlatformApp("empty_context_menu");
130 107
131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 108 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
132 109
133 // The empty app doesn't add any context menu items, so its menu should 110 // The empty app doesn't add any context menu items, so its menu should
134 // only include the developer tools. 111 // only include the developer tools.
135 WebContents* web_contents = GetFirstPlatformAppShellWindowWebContents(); 112 WebContents* web_contents = GetFirstShellWindowWebContents();
136 ASSERT_TRUE(web_contents); 113 ASSERT_TRUE(web_contents);
137 WebKit::WebContextMenuData data; 114 WebKit::WebContextMenuData data;
138 content::ContextMenuParams params(data); 115 content::ContextMenuParams params(data);
139 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 116 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
140 params); 117 params);
141 menu->Init(); 118 menu->Init();
119 // TODO(benwells): Remove the constant below. Instead of checking the
120 // number of menu items check certain item's absense and presence.
142 // 3 including separator 121 // 3 including separator
143 ASSERT_EQ(3, menu->menu_model().GetItemCount()); 122 ASSERT_EQ(3, menu->menu_model().GetItemCount());
144 } 123 }
145 124
146 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { 125 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) {
147 ExtensionTestMessageListener launched_listener("Launched", false); 126 ExtensionTestMessageListener launched_listener("Launched", false);
148 LoadAndLaunchPlatformApp("context_menu"); 127 LoadAndLaunchPlatformApp("context_menu");
149 128
150 // Wait for the extension to tell us it's initialized its context menus and 129 // Wait for the extension to tell us it's initialized its context menus and
151 // launched a window. 130 // launched a window.
152 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
153 132
154 // The context_menu app has one context menu item. This, along with a 133 // The context_menu app has one context menu item. This, along with a
155 // separator and the developer tools, is all that should be in the menu. 134 // separator and the developer tools, is all that should be in the menu.
156 WebContents* web_contents = GetFirstPlatformAppShellWindowWebContents(); 135 WebContents* web_contents = GetFirstShellWindowWebContents();
157 ASSERT_TRUE(web_contents); 136 ASSERT_TRUE(web_contents);
158 WebKit::WebContextMenuData data; 137 WebKit::WebContextMenuData data;
159 content::ContextMenuParams params(data); 138 content::ContextMenuParams params(data);
160 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents, 139 PlatformAppContextMenu* menu = new PlatformAppContextMenu(web_contents,
161 params); 140 params);
162 menu->Init(); 141 menu->Init();
142 // TODO(benwells): Remove the constant below. Instead of checking the
143 // number of menu items check certain item's absense and presence.
163 ASSERT_EQ(4, menu->menu_model().GetItemCount()); 144 ASSERT_EQ(4, menu->menu_model().GetItemCount());
164 } 145 }
165 146
166 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) { 147 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowNavigation) {
167 ASSERT_TRUE(StartTestServer()); 148 ASSERT_TRUE(StartTestServer());
168 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_; 149 ASSERT_TRUE(RunPlatformAppTest("platform_apps/navigation")) << message_;
169 } 150 }
170 151
171 // Tests that localStorage and WebSQL are disabled for platform apps. 152 // Tests that localStorage and WebSQL are disabled for platform apps.
172 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) { 153 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, DisallowStorage) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 set_cookie_url, 186 set_cookie_url,
206 browser()->GetWebContentsAt(0), 187 browser()->GetWebContentsAt(0),
207 &cookie_size, 188 &cookie_size,
208 &cookie_value); 189 &cookie_value);
209 ASSERT_EQ("testCookie=1", cookie_value); 190 ASSERT_EQ("testCookie=1", cookie_value);
210 191
211 // Let the platform app request the same URL, and make sure that it doesn't 192 // Let the platform app request the same URL, and make sure that it doesn't
212 // see the cookie. 193 // see the cookie.
213 ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_; 194 ASSERT_TRUE(RunPlatformAppTest("platform_apps/isolation")) << message_;
214 } 195 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.cc ('k') | chrome/browser/extensions/shell_window_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698