blob: f84244fb5b070c6717a2142331cbf48eb1c9e16f [file] [log] [blame]
[email protected]937cf9d2012-08-30 03:51:551// 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.
4
[email protected]937cf9d2012-08-30 03:51:555#include "base/memory/scoped_ptr.h"
[email protected]b19fe572013-07-18 04:54:266#include "base/message_loop/message_loop.h"
[email protected]3853a4c2013-02-11 17:15:577#include "base/prefs/pref_service.h"
[email protected]937cf9d2012-08-30 03:51:558#include "chrome/browser/extensions/default_apps.h"
[email protected]e0ec3cb12013-04-03 17:35:309#include "chrome/browser/extensions/external_pref_loader.h"
[email protected]937cf9d2012-08-30 03:51:5510#include "chrome/common/chrome_paths.h"
[email protected]937cf9d2012-08-30 03:51:5511#include "chrome/common/pref_names.h"
12#include "chrome/test/base/testing_profile.h"
13#include "content/public/test/test_browser_thread.h"
[email protected]e4452d32013-11-15 23:07:4114#include "extensions/common/extension.h"
[email protected]937cf9d2012-08-30 03:51:5515#include "testing/gtest/include/gtest/gtest.h"
16
17using default_apps::Provider;
[email protected]e0ec3cb12013-04-03 17:35:3018
19namespace extensions {
[email protected]937cf9d2012-08-30 03:51:5520
21class MockExternalLoader : public ExternalLoader {
22 public:
23 MockExternalLoader() {}
24
[email protected]49aeab62013-02-07 02:53:1125 virtual void StartLoading() OVERRIDE {}
[email protected]937cf9d2012-08-30 03:51:5526 private:
27 virtual ~MockExternalLoader() {}
28};
29
30class DefaultAppsTest : public testing::Test {
31 public:
[email protected]1ef90012014-01-15 22:24:3332 DefaultAppsTest() : ui_thread_(content::BrowserThread::UI, &loop_) {}
[email protected]937cf9d2012-08-30 03:51:5533 virtual ~DefaultAppsTest() {}
34 private:
[email protected]1ef90012014-01-15 22:24:3335 base::MessageLoopForIO loop_;
[email protected]937cf9d2012-08-30 03:51:5536 content::TestBrowserThread ui_thread_;
37};
38
[email protected]13e062e2014-08-09 10:21:5539#if !defined(OS_CHROMEOS)
[email protected]937cf9d2012-08-30 03:51:5540// Chrome OS has different way of installing default apps.
[email protected]3ed92b8e2012-08-30 17:59:2341// Android does not currently support installing apps via Chrome.
[email protected]937cf9d2012-08-30 03:51:5542TEST_F(DefaultAppsTest, Install) {
43 scoped_ptr<TestingProfile> profile(new TestingProfile());
[email protected]e0ec3cb12013-04-03 17:35:3044 ExternalLoader* loader = new MockExternalLoader();
[email protected]937cf9d2012-08-30 03:51:5545
[email protected]1d5e58b2013-01-31 08:41:4046 Provider provider(profile.get(), NULL, loader, Manifest::INTERNAL,
47 Manifest::INTERNAL, Extension::NO_FLAGS);
[email protected]937cf9d2012-08-30 03:51:5548
49 // The default apps should be installed if kDefaultAppsInstallState
50 // is unknown.
51 EXPECT_TRUE(provider.ShouldInstallInProfile());
52 int state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
53 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
54
55 // The default apps should only be installed once.
56 EXPECT_FALSE(provider.ShouldInstallInProfile());
57 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
58 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
59
60 // The default apps should not be installed if the state is
61 // kNeverProvideDefaultApps
62 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
63 default_apps::kNeverInstallDefaultApps);
64 EXPECT_FALSE(provider.ShouldInstallInProfile());
65 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
66 EXPECT_TRUE(state == default_apps::kNeverInstallDefaultApps);
67
68 // The old default apps with kAlwaysInstallDefaultAppss should be migrated.
69 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
70 default_apps::kProvideLegacyDefaultApps);
71 EXPECT_TRUE(provider.ShouldInstallInProfile());
72 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
73 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
74
75 class DefaultTestingProfile : public TestingProfile {
76 virtual bool WasCreatedByVersionOrLater(
77 const std::string& version) OVERRIDE {
78 return false;
79 }
80 };
81 profile.reset(new DefaultTestingProfile);
[email protected]1d5e58b2013-01-31 08:41:4082 Provider provider2(profile.get(), NULL, loader, Manifest::INTERNAL,
83 Manifest::INTERNAL, Extension::NO_FLAGS);
[email protected]937cf9d2012-08-30 03:51:5584 // The old default apps with kProvideLegacyDefaultApps should be migrated
85 // even if the profile version is older than Chrome version.
86 profile->GetPrefs()->SetInteger(prefs::kDefaultAppsInstallState,
87 default_apps::kProvideLegacyDefaultApps);
88 EXPECT_TRUE(provider2.ShouldInstallInProfile());
89 state = profile->GetPrefs()->GetInteger(prefs::kDefaultAppsInstallState);
90 EXPECT_TRUE(state == default_apps::kAlreadyInstalledDefaultApps);
91}
92#endif
[email protected]e0ec3cb12013-04-03 17:35:3093
94} // namespace extensions