1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "chrome/browser/extensions/apps_promo.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/ui/webui/shown_sections_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/testing_browser_process.h"
#include "chrome/test/testing_pref_service.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kPromoId[] = "23123123";
const char kPromoHeader[] = "Get great apps!";
const char kPromoButton[] = "Click for apps!";
const char kPromoLink[] = "http://apps.com";
const char kPromoExpire[] = "No thanks.";
} // namespace
class ExtensionAppsPromo : public testing::Test {
public:
TestingPrefService* local_state() { return &local_state_; }
TestingPrefService* prefs() { return &prefs_; }
AppsPromo* apps_promo() { return apps_promo_; }
protected:
explicit ExtensionAppsPromo();
virtual ~ExtensionAppsPromo();
// testing::Test
virtual void SetUp();
virtual void TearDown();
private:
TestingPrefService local_state_;
TestingPrefService prefs_;
AppsPromo* apps_promo_;
};
ExtensionAppsPromo::ExtensionAppsPromo() :
apps_promo_(new AppsPromo(&prefs_)) {
}
ExtensionAppsPromo::~ExtensionAppsPromo() {
delete apps_promo_;
}
void ExtensionAppsPromo::SetUp() {
browser::RegisterLocalState(&local_state_);
browser::RegisterUserPrefs(&prefs_);
TestingBrowserProcess* testing_browser_process =
static_cast<TestingBrowserProcess*>(g_browser_process);
testing_browser_process->SetPrefService(&local_state_);
}
void ExtensionAppsPromo::TearDown() {
TestingBrowserProcess* testing_browser_process =
static_cast<TestingBrowserProcess*>(g_browser_process);
testing_browser_process->SetPrefService(NULL);
}
// TODO(dpolukhin): On Chrome OS all apps are installed via external extensions,
// and the web store promo is never shown.
#if !defined(OS_CHROMEOS)
TEST_F(ExtensionAppsPromo, HappyPath) {
const ExtensionIdSet& default_app_ids = apps_promo()->old_default_apps();
EXPECT_GT(default_app_ids.size(), 0u);
// The promo counter should default to the max, since we only use the counter
// if they were installed from older versions of Chrome.
EXPECT_EQ(AppsPromo::kDefaultAppsCounterMax + 1,
apps_promo()->GetPromoCounter());
// The app launcher and promo should not be shown if there are no extensions
// installed and no promo is set.
ExtensionIdSet installed_ids;
bool promo_just_expired = false;
EXPECT_FALSE(AppsPromo::IsPromoSupportedForLocale());
EXPECT_FALSE(apps_promo()->ShouldShowAppLauncher(installed_ids));
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
&promo_just_expired));
EXPECT_FALSE(promo_just_expired);
// Once the promo is set, we show both the promo and app launcher.
AppsPromo::SetPromo(
kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire);
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
EXPECT_TRUE(apps_promo()->ShouldShowPromo(installed_ids,
&promo_just_expired));
EXPECT_FALSE(promo_just_expired);
// Now install an app and the promo should not be shown.
installed_ids.insert(*(default_app_ids.begin()));
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
&promo_just_expired));
EXPECT_FALSE(promo_just_expired);
// Even if the user installs the exact set of default apps, we still don't
// show the promo.
installed_ids = default_app_ids;
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
&promo_just_expired));
EXPECT_FALSE(promo_just_expired);
// If the user then uninstalls the apps, the app launcher should remain
// and the promo should return.
installed_ids.clear();
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
EXPECT_TRUE(apps_promo()->ShouldShowAppLauncher(installed_ids));
EXPECT_TRUE(apps_promo()->ShouldShowPromo(installed_ids,
&promo_just_expired));
EXPECT_FALSE(promo_just_expired);
}
// Tests get and set of promo content.
TEST_F(ExtensionAppsPromo, PromoPrefs) {
// Store a promo....
AppsPromo::SetPromo(
kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire);
// ... then make sure AppsPromo can access it.
EXPECT_EQ(kPromoId, AppsPromo::GetPromoId());
EXPECT_EQ(kPromoHeader, AppsPromo::GetPromoHeaderText());
EXPECT_EQ(kPromoButton, AppsPromo::GetPromoButtonText());
EXPECT_EQ(GURL(kPromoLink), AppsPromo::GetPromoLink());
EXPECT_EQ(kPromoExpire, AppsPromo::GetPromoExpireText());
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
AppsPromo::ClearPromo();
EXPECT_EQ("", AppsPromo::GetPromoId());
EXPECT_EQ("", AppsPromo::GetPromoHeaderText());
EXPECT_EQ("", AppsPromo::GetPromoButtonText());
EXPECT_EQ(GURL(""), AppsPromo::GetPromoLink());
EXPECT_EQ("", AppsPromo::GetPromoExpireText());
EXPECT_FALSE(AppsPromo::IsPromoSupportedForLocale());
}
// Tests that the apps section is maxmized when showing a promo for the first
// time.
TEST_F(ExtensionAppsPromo, UpdatePromoFocus) {
ExtensionIdSet installed_ids;
bool promo_just_expired = false;
EXPECT_FALSE(apps_promo()->ShouldShowPromo(installed_ids,
&promo_just_expired));
EXPECT_FALSE(promo_just_expired);
// Set the promo content.
AppsPromo::SetPromo(
kPromoId, kPromoHeader, kPromoButton, GURL(kPromoLink), kPromoExpire);
// After asking if we should show the promo, the
EXPECT_TRUE(AppsPromo::IsPromoSupportedForLocale());
EXPECT_TRUE(apps_promo()->ShouldShowPromo(installed_ids,
&promo_just_expired));
apps_promo()->MaximizeAppsIfFirstView();
EXPECT_TRUE(
(ShownSectionsHandler::GetShownSections(prefs()) & APPS) != 0);
EXPECT_FALSE(
(ShownSectionsHandler::GetShownSections(prefs()) & THUMB) != 0);
apps_promo()->HidePromo();
EXPECT_TRUE((ShownSectionsHandler::GetShownSections(prefs()) &
(MENU_APPS | THUMB)) != 0);
}
#endif // OS_CHROMEOS
|