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

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: Apply mws' comments 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
« no previous file with comments | « apps/app_load_service.cc ('k') | chrome/browser/extensions/extension_system_impl.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 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/strings/utf_string_conversions.h"
11 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
12 #include "chrome/browser/apps/app_browsertest_util.h" 13 #include "chrome/browser/apps/app_browsertest_util.h"
13 #include "chrome/browser/extensions/extension_browsertest.h" 14 #include "chrome/browser/extensions/extension_browsertest.h"
15 #include "chrome/browser/extensions/extension_error_reporter.h"
14 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/simple_message_box_internal.h"
15 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
16 #include "content/public/common/content_switches.h" 19 #include "content/public/common/content_switches.h"
17 #include "content/public/test/test_launcher.h" 20 #include "content/public/test/test_launcher.h"
21 #include "extensions/browser/extension_registry.h"
18 #include "extensions/test/extension_test_message_listener.h" 22 #include "extensions/test/extension_test_message_listener.h"
23 #include "testing/gmock/include/gmock/gmock.h"
msw 2016/07/25 23:44:46 nit: remove
proberge 2016/07/26 15:09:58 Done.
24 #include "testing/gtest/include/gtest/gtest.h"
msw 2016/07/25 23:44:46 optional nit: remove; included via extension_brows
proberge 2016/07/26 15:09:57 Done.
19 25
20 using extensions::PlatformAppBrowserTest; 26 using extensions::PlatformAppBrowserTest;
21 27
22 namespace apps { 28 namespace apps {
23 29
24 namespace { 30 namespace {
25 31
26 const char* kSwitchesToCopy[] = { 32 const char* kSwitchesToCopy[] = {
27 switches::kUserDataDir, 33 switches::kUserDataDir,
28 switches::kNoSandbox, 34 switches::kNoSandbox,
29 }; 35 };
30 36
37 static const std::string kTestExtensionId_("behllobkkfkfnphdnhnkndlbkcpglgmj");
msw 2016/07/25 23:44:46 nit: no trailing underscore.
proberge 2016/07/26 15:09:57 Done.
38
31 } // namespace 39 } // namespace
32 40
33 // TODO(jackhou): Enable this test once it works on OSX. It currently does not 41 // TODO(jackhou): Enable this test once it works on OSX. It currently does not
34 // work for the same reason --app-id doesn't. See http://crbug.com/148465 42 // work for the same reason --app-id doesn't. See http://crbug.com/148465
35 #if defined(OS_MACOSX) 43 #if defined(OS_MACOSX)
36 #define MAYBE_LoadAndLaunchAppChromeRunning \ 44 #define MAYBE_LoadAndLaunchAppChromeRunning \
37 DISABLED_LoadAndLaunchAppChromeRunning 45 DISABLED_LoadAndLaunchAppChromeRunning
38 #else 46 #else
39 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning 47 #define MAYBE_LoadAndLaunchAppChromeRunning LoadAndLaunchAppChromeRunning
40 #endif 48 #endif
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 113
106 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 114 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
107 int exit_code; 115 int exit_code;
108 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(), 116 ASSERT_TRUE(process.WaitForExitWithTimeout(TestTimeouts::action_timeout(),
109 &exit_code)); 117 &exit_code));
110 ASSERT_EQ(0, exit_code); 118 ASSERT_EQ(0, exit_code);
111 } 119 }
112 120
113 namespace { 121 namespace {
114 122
115 // TestFixture that appends --load-and-launch-app before calling BrowserMain. 123 // TestFixture that appends --load-and-launch-app with an app before calling
116 class PlatformAppLoadAndLaunchBrowserTest : public PlatformAppBrowserTest { 124 // BrowserMain.
125 class LoadAndLaunchPlatformAppBrowserTest : public PlatformAppBrowserTest {
117 protected: 126 protected:
118 PlatformAppLoadAndLaunchBrowserTest() {} 127 LoadAndLaunchPlatformAppBrowserTest() {}
119 128
120 void SetUpCommandLine(base::CommandLine* command_line) override { 129 void SetUpCommandLine(base::CommandLine* command_line) override {
121 PlatformAppBrowserTest::SetUpCommandLine(command_line); 130 PlatformAppBrowserTest::SetUpCommandLine(command_line);
122 app_path_ = test_data_dir_ 131 base::FilePath app_path =
123 .AppendASCII("platform_apps") 132 test_data_dir_.AppendASCII("platform_apps").AppendASCII("minimal");
124 .AppendASCII("minimal"); 133 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, app_path.value());
125 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp,
126 app_path_.value());
127 } 134 }
128 135
129 void LoadAndLaunchApp() { 136 void LoadAndLaunchApp() {
130 ExtensionTestMessageListener launched_listener("Launched", false); 137 ExtensionTestMessageListener launched_listener("Launched", false);
131 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); 138 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
132 139
133 // Start an actual browser because we can't shut down with just an app 140 // Start an actual browser because we can't shut down with just an app
134 // window. 141 // window.
135 CreateBrowser(ProfileManager::GetActiveUserProfile()); 142 CreateBrowser(ProfileManager::GetActiveUserProfile());
136 } 143 }
137 144
138 private: 145 private:
139 base::FilePath app_path_; 146 DISALLOW_COPY_AND_ASSIGN(LoadAndLaunchPlatformAppBrowserTest);
147 };
140 148
141 DISALLOW_COPY_AND_ASSIGN(PlatformAppLoadAndLaunchBrowserTest); 149 // TestFixture that appends --load-and-launch-app with an extension before
150 // calling BrowserMain.
151 class LoadAndLaunchExtensionBrowserTest : public PlatformAppBrowserTest {
152 protected:
153 LoadAndLaunchExtensionBrowserTest() {}
154
155 void SetUpCommandLine(base::CommandLine* command_line) override {
156 PlatformAppBrowserTest::SetUpCommandLine(command_line);
157 base::FilePath app_path = test_data_dir_.AppendASCII("good")
158 .AppendASCII("Extensions")
159 .AppendASCII(kTestExtensionId_)
160 .AppendASCII("1.0.0.0");
161 command_line->AppendSwitchNative(apps::kLoadAndLaunchApp, app_path.value());
162 }
163
164 void SetUpInProcessBrowserTestFixture() override {
165 PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture();
166
167 // Skip showing the error message box to avoid freezing the main thread.
168 chrome::internal::g_should_skip_message_box_for_test = true;
169 }
170
171 DISALLOW_COPY_AND_ASSIGN(LoadAndLaunchExtensionBrowserTest);
142 }; 172 };
143 173
144 } // namespace 174 } // namespace
145 175
146 176
147 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See 177 // TODO(jackhou): Make this test not flaky on Vista or Linux Aura. See
148 // http://crbug.com/176897 178 // http://crbug.com/176897
149 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA)) 179 #if defined(OS_WIN) || (defined(OS_LINUX) && defined(USE_AURA))
150 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ 180 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
151 DISABLED_LoadAndLaunchAppChromeNotRunning 181 DISABLED_LoadAndLaunchAppChromeNotRunning
152 #else 182 #else
153 #define MAYBE_LoadAndLaunchAppChromeNotRunning \ 183 #define MAYBE_LoadAndLaunchAppChromeNotRunning \
154 LoadAndLaunchAppChromeNotRunning 184 LoadAndLaunchAppChromeNotRunning
155 #endif 185 #endif
156 186
157 // Case where Chrome is not running. 187 // Case where Chrome is not running.
158 IN_PROC_BROWSER_TEST_F(PlatformAppLoadAndLaunchBrowserTest, 188 IN_PROC_BROWSER_TEST_F(LoadAndLaunchPlatformAppBrowserTest,
159 MAYBE_LoadAndLaunchAppChromeNotRunning) { 189 MAYBE_LoadAndLaunchAppChromeNotRunning) {
160 LoadAndLaunchApp(); 190 LoadAndLaunchApp();
161 } 191 }
162 192
193 IN_PROC_BROWSER_TEST_F(LoadAndLaunchExtensionBrowserTest,
194 LoadAndLaunchExtension) {
195 const std::vector<base::string16>* errors =
196 ExtensionErrorReporter::GetInstance()->GetErrors();
197
198 #if defined(GOOGLE_CHROME_BUILD)
199 // The error is skipped on official builds.
200 EXPECT_EQ(0u, errors->size());
msw 2016/07/25 23:44:46 optional nit: EXPECT_TRUE(errors->empty());
proberge 2016/07/26 15:09:57 Done.
201 #else
202 // Expect kUnpackedExtensionInsteadOfAppError.
203 EXPECT_EQ(1u, errors->size());
204 EXPECT_THAT(base::UTF16ToUTF8(errors->at(0)),
msw 2016/07/25 23:44:46 nit: consider doing this instead: EXPECT_NE(base
proberge 2016/07/26 15:09:57 Done without the ASCIIToUTF16 and with ->at(0) ins
205 testing::HasSubstr(
206 "App loading flags cannot be used to load extensions"));
207 #endif
208
209 extensions::ExtensionRegistry* registry =
210 extensions::ExtensionRegistry::Get(profile());
211 EXPECT_EQ(nullptr,
212 registry->GetExtensionById(
213 kTestExtensionId_, extensions::ExtensionRegistry::EVERYTHING));
214 }
215
163 } // namespace apps 216 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_load_service.cc ('k') | chrome/browser/extensions/extension_system_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698