blob: daa442d94e95eaaf194f1a3cc4800f04ab038220 [file] [log] [blame]
Devlin Cronin8c23eec2018-05-01 18:42:281// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/macros.h"
6#include "chrome/browser/extensions/extension_browsertest.h"
7#include "chrome/common/chrome_switches.h"
8#include "extensions/browser/extension_prefs.h"
9#include "extensions/browser/extension_registry.h"
10#include "extensions/common/extension.h"
11#include "extensions/common/extension_set.h"
12#include "extensions/common/manifest.h"
13
14namespace extensions {
15
16namespace {
17constexpr char kGoodExtensionId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
18constexpr char kSimpleWithKeyExtensionId[] = "iegclhlplifhodhkoafiokenjoapiobj";
19} // namespace
20
21class ExtensionsDisabledBrowserTest : public ExtensionBrowserTest {
22 public:
23 ExtensionsDisabledBrowserTest() = default;
24 ~ExtensionsDisabledBrowserTest() override = default;
25 void SetUpCommandLine(base::CommandLine* command_line) override {
26 // A little tricky: we disable extensions (via the commandline) on the
27 // non-PRE run. The PRE run is responsible for installing the external
28 // extension.
29 ExtensionBrowserTest::SetUpCommandLine(command_line);
30 const char* test_name =
31 testing::UnitTest::GetInstance()->current_test_info()->name();
32 if (!base::StartsWith(test_name, "PRE_", base::CompareCase::SENSITIVE)) {
33 command_line->AppendSwitch(::switches::kDisableExtensions);
34 }
35 }
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(ExtensionsDisabledBrowserTest);
39};
40
41// Tests installing a number of extensions, and then restarting Chrome with the
42// --disable-extensions switch. Regression test for https://crbug.com/836624.
43IN_PROC_BROWSER_TEST_F(ExtensionsDisabledBrowserTest,
44 PRE_TestStartupWithInstalledExtensions) {
45 const Extension* unpacked_extension =
46 LoadExtension(test_data_dir_.AppendASCII("simple_with_key"));
47 ASSERT_TRUE(unpacked_extension);
48 EXPECT_EQ(Manifest::UNPACKED, unpacked_extension->location());
49
50 const Extension* internal_extension =
51 LoadExtension(test_data_dir_.AppendASCII("good.crx"));
52 ASSERT_TRUE(internal_extension);
53 EXPECT_EQ(Manifest::INTERNAL, internal_extension->location());
54
55 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
56 EXPECT_TRUE(registry->enabled_extensions().GetByID(kGoodExtensionId));
57 EXPECT_TRUE(
58 registry->enabled_extensions().GetByID(kSimpleWithKeyExtensionId));
59
60 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
61 EXPECT_TRUE(prefs->GetInstalledExtensionInfo(kGoodExtensionId));
62 EXPECT_TRUE(prefs->GetInstalledExtensionInfo(kSimpleWithKeyExtensionId));
63}
64IN_PROC_BROWSER_TEST_F(ExtensionsDisabledBrowserTest,
65 TestStartupWithInstalledExtensions) {
66 EXPECT_TRUE(ExtensionsBrowserClient::Get()->AreExtensionsDisabled(
67 *base::CommandLine::ForCurrentProcess(), profile()));
68
69 // Neither of the installed extensions should have been loaded or added to
70 // the registry.
71 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
72 EXPECT_FALSE(registry->GetInstalledExtension(kGoodExtensionId));
73 EXPECT_FALSE(registry->GetInstalledExtension(kSimpleWithKeyExtensionId));
74
75 // However, they should still be stored in the preferences.
76 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile());
77 EXPECT_TRUE(prefs->GetInstalledExtensionInfo(kGoodExtensionId));
78 EXPECT_TRUE(prefs->GetInstalledExtensionInfo(kSimpleWithKeyExtensionId));
79}
80
81} // namespace extensions