Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / extensions / default_apps_unittest.cc
blob25db9107fbce107ca1bf2a8609e3eef49f792447
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
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/extensions/default_apps.h"
9 #include "chrome/browser/extensions/external_pref_loader.h"
10 #include "chrome/common/chrome_paths.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "extensions/common/extension.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 using default_apps::Provider;
19 namespace extensions {
21 class MockExternalLoader : public ExternalLoader {
22 public:
23 MockExternalLoader() {}
25 void StartLoading() override {}
27 private:
28 ~MockExternalLoader() override {}
31 class DefaultAppsTest : public testing::Test {
32 public:
33 DefaultAppsTest() : ui_thread_(content::BrowserThread::UI, &loop_) {}
34 ~DefaultAppsTest() override {}
36 private:
37 base::MessageLoopForIO loop_;
38 content::TestBrowserThread ui_thread_;
41 #if !defined(OS_CHROMEOS)
42 // Chrome OS has different way of installing default apps.
43 // Android does not currently support installing apps via Chrome.
44 TEST_F(DefaultAppsTest, Install) {
45 scoped_ptr<TestingProfile> profile(new TestingProfile());
46 ExternalLoader* loader = new MockExternalLoader();
48 Provider provider(profile.get(), NULL, loader, Manifest::INTERNAL,
49 Manifest::INTERNAL, Extension::NO_FLAGS);
51 // The default apps should be installed if kDefaultAppsInstallState
52 // is unknown.
53 EXPECT_TRUE(provider.ShouldInstallInProfile());
54 int state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
55 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
57 // The default apps should only be installed once.
58 EXPECT_FALSE(provider.ShouldInstallInProfile());
59 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
60 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
62 // The default apps should not be installed if the state is
63 // kNeverProvideDefaultApps
64 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
65 default_apps::kNeverInstallDefaultApps);
66 EXPECT_FALSE(provider.ShouldInstallInProfile());
67 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
68 EXPECT_TRUE(state == default_apps::kNeverInstallDefaultApps);
70 // The old default apps with kAlwaysInstallDefaultAppss should be migrated.
71 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
72 default_apps::kProvideLegacyDefaultApps);
73 EXPECT_TRUE(provider.ShouldInstallInProfile());
74 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
75 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
77 class DefaultTestingProfile : public TestingProfile {
78 bool WasCreatedByVersionOrLater(const std::string& version) override {
79 return false;
82 profile.reset(new DefaultTestingProfile);
83 Provider provider2(profile.get(), NULL, loader, Manifest::INTERNAL,
84 Manifest::INTERNAL, Extension::NO_FLAGS);
85 // The old default apps with kProvideLegacyDefaultApps should be migrated
86 // even if the profile version is older than Chrome version.
87 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
88 default_apps::kProvideLegacyDefaultApps);
89 EXPECT_TRUE(provider2.ShouldInstallInProfile());
90 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
91 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
93 #endif
95 } // namespace extensions