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

Side by Side Diff: apps/load_and_launch_browsertest.cc

Issue 2108853002: Restrict use of two app-launching command line flags (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add /* explanation */ for the bool parameter Created 4 years, 5 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 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 // Tests for the --load-and-launch-app switch. 5 // Tests for the --load-and-launch-app switch.
6 // The two cases are when chrome is running and another process uses the switch 6 // The two cases are when chrome is running and another process uses the switch
7 // and when chrome is started from scratch. 7 // and when chrome is started from scratch.
8 8
9 #include "apps/switches.h" 9 #include "apps/switches.h"
10 #include "base/process/launch.h" 10 #include "base/process/launch.h"
11 #include "base/test/test_timeouts.h" 11 #include "base/test/test_timeouts.h"
12 #include "chrome/browser/apps/app_browsertest_util.h" 12 #include "chrome/browser/apps/app_browsertest_util.h"
13 #include "chrome/browser/extensions/extension_browsertest.h" 13 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_error_reporter.h"
14 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/simple_message_box_internal.h"
15 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
16 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
17 #include "content/public/test/test_launcher.h" 19 #include "content/public/test/test_launcher.h"
20 #include "extensions/browser/extension_registry.h"
18 #include "extensions/test/extension_test_message_listener.h" 21 #include "extensions/test/extension_test_message_listener.h"
19 22
20 using extensions::PlatformAppBrowserTest; 23 using extensions::PlatformAppBrowserTest;
21 24
22 namespace apps { 25 namespace apps {
23 26
24 namespace { 27 namespace {
25 28
26 const char* kSwitchesToCopy[] = { 29 const char* kSwitchesToCopy[] = {
27 switches::kUserDataDir, 30 switches::kUserDataDir,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 108
106 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 109 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
107 int exit_code; 110 int exit_code;
108 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), 111 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
109 &exit_code)); 112 &exit_code));
110 ASSERT_EQ(0, exit_code); 113 ASSERT_EQ(0, exit_code);
111 } 114 }
112 115
113 namespace { 116 namespace {
114 117
115 // TestFixture that appends --load-and-launch-app before calling BrowserMain. 118 // TestFixture that appends --load-and-launch-app with an app before calling
119 // BrowserMain.
116 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest { 120 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest {
msw 2016/07/21 17:13:49 optional nit: LoadAndLaunchPlatformAppBrowserTest
proberge 2016/07/25 20:40:53 Done.
117 protected: 121 protected:
118 PlatformAppLoadAndLaunchBrowserTest() {} 122 PlatformAppLoadAndLaunchBrowserTest() {}
119 123
120 void SetUpCommandLine(base::CommandLine* command_line) override { 124 void SetUpCommandLine(base::CommandLine* command_line) override {
121 PlatformAppBrowserTest::SetUpCommandLine(command_line); 125 PlatformAppBrowserTest::SetUpCommandLine(command_line);
122 app_path_ = test_data_dir_ 126 app_path_ = test_data_dir_
msw 2016/07/21 17:13:50 optional nit: not used elsewhere; make this functi
proberge 2016/07/25 20:40:53 Done.
123 .AppendASCII("platform_apps") 127 .AppendASCII("platform_apps")
124 .AppendASCII("minimal"); 128 .AppendASCII("minimal");
125 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, 129 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
126 app_path_.value()); 130 app_path_.value());
127 } 131 }
128 132
129 void LoadAndLaunchApp() { 133 void LoadAndLaunchApp() {
130 ExtensionTestMessageListener launched_listener("Launched", false); 134 ExtensionTestMessageListener launched_listener("Launched", false);
131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 135 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
132 136
133 // Start an actual browser because we can't shut down with just an app 137 // Start an actual browser because we can't shut down with just an app
134 // window. 138 // window.
135 CreateBrowser(ProfileManager::GetActiveUserProfile()); 139 CreateBrowser(ProfileManager::GetActiveUserProfile());
136 } 140 }
137 141
138 private: 142 private:
139 base::FilePath app_path_; 143 base::FilePath app_path_;
140 144
141 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest); 145 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest);
142 }; 146 };
143 147
148 // TestFixture that appends --load-and-launch-app with an extension before
149 // calling BrowserMain.
150 class LoadAndLaunchExtensionBrowserTest : public PlatformAppBrowserTest {
151 protected:
152 LoadAndLaunchExtensionBrowserTest() {}
153
154 void SetUpCommandLine(base::CommandLine* command_line) override {
155 PlatformAppBrowserTest::SetUpCommandLine(command_line);
156 app_path_ = test_data_dir_.AppendASCII("good")
msw 2016/07/21 17:13:50 nit: not used elsewhere; make this function-local.
proberge 2016/07/25 20:40:53 Done.
157 .AppendASCII("Extensions")
158 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
msw 2016/07/21 17:13:50 nit: cache extension id string (file-local static?
proberge 2016/07/25 20:40:53 Done.
159 .AppendASCII("1.0.0.0");
160 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
161 app_path_.value());
162 }
163
164 void SetUpInProcessBrowserTestFixture() override {
165 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture();
166
167 // Skip showing the error message box in order to avoid freezing the main
msw 2016/07/21 17:13:50 optional nit: -'in order' for a one-liner
proberge 2016/07/25 20:40:53 Done.
168 // thread.
169 chrome::internal::g_should_skip_message_box_for_test = true;
170 }
171
172 private:
173 base::FilePath app_path_;
174
175 DISALLOW_COPY_AND_ASSIGN(LoadAndLaunchExtensionBrowserTest);
176 };
177
144 } // namespace 178 } // namespace
145 179
146 180
147 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See 181 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See
msw 2016/07/21 17:13:50 Would you mind trying to re-enable this test in a
proberge 2016/07/25 20:40:53 Sure, I'll try in a follow-up CL.
148 // http://crbug.com/176897 182 // http://crbug.com/176897
149 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA)) 183 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA))
150 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ 184 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
151 DISABLED_LoadAndLaunchAppChromeNotRunning 185 DISABLED_LoadAndLaunchAppChromeNotRunning
152 #else 186 #else
153 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ 187 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
154 LoadAndLaunchAppChromeNotRunning 188 LoadAndLaunchAppChromeNotRunning
155 #endif 189 #endif
156 190
157 // Case where Chrome is not running. 191 // Case where Chrome is not running.
158 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest, 192 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest,
159 MAYBE_LoadAndLaunchAppChromeNotRunning) { 193 MAYBE_LoadAndLaunchAppChromeNotRunning) {
160 LoadAndLaunchApp(); 194 LoadAndLaunchApp();
msw 2016/07/21 17:13:50 optional nit: check that the app actually loaded?
proberge 2016/07/25 20:40:53 Will do once the test is re-enabled.
161 } 195 }
162 196
197 IN_PROC_BROWSER_TEST_F(LoadAndLaunchExtensionBrowserTest,
198 LoadAndLaunchExtension) {
199 const std::vector<base::string16>* errors =
200 ExtensionErrorReporter::GetInstance()->GetErrors();
201
202 // Expect kUnpackedExtensionInsteadOfAppError.
msw 2016/07/21 17:13:49 nit: check for this value?
proberge 2016/07/25 20:40:53 Done.
203 EXPECT_EQ(1u, errors->size());
msw 2016/07/21 17:13:50 Does this ever run on official builds? If so, it'l
proberge 2016/07/25 20:40:53 Good catch! Thanks
204
205 extensions::ExtensionRegistry* registry =
206 extensions::ExtensionRegistry::Get(profile());
207 EXPECT_EQ(nullptr, registry->GetExtensionById(
208 "behllobkkfkfnphdnhnkndlbkcpglgmj",
209 extensions::ExtensionRegistry::EVERYTHING));
210 }
211
163 } // namespace apps 212 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698