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

Side by Side Diff: chrome/browser/installable/installable_manager_browsertest.cc

Issue 2944283002: Replace --add-to-shelf flag with kAppBanners feature. (Closed)
Patch Set: Self nit Created 3 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "chrome/browser/installable/installable_manager.h" 5 #include "chrome/browser/installable/installable_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/test/scoped_feature_list.h"
9 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_features.h"
13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
15 #include "net/test/embedded_test_server/embedded_test_server.h" 16 #include "net/test/embedded_test_server/embedded_test_server.h"
16 17
17 using IconPurpose = content::Manifest::Icon::IconPurpose; 18 using IconPurpose = content::Manifest::Icon::IconPurpose;
18 19
19 namespace { 20 namespace {
20 21
21 const std::tuple<int, int, IconPurpose> kPrimaryIconParams{144, 144, 22 const std::tuple<int, int, IconPurpose> kPrimaryIconParams{144, 144,
22 IconPurpose::ANY}; 23 IconPurpose::ANY};
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 GURL primary_icon_url_; 151 GURL primary_icon_url_;
151 std::unique_ptr<SkBitmap> primary_icon_; 152 std::unique_ptr<SkBitmap> primary_icon_;
152 bool is_installable_; 153 bool is_installable_;
153 }; 154 };
154 155
155 class InstallableManagerBrowserTest : public InProcessBrowserTest { 156 class InstallableManagerBrowserTest : public InProcessBrowserTest {
156 public: 157 public:
157 void SetUpOnMainThread() override { 158 void SetUpOnMainThread() override {
158 InProcessBrowserTest::SetUpOnMainThread(); 159 InProcessBrowserTest::SetUpOnMainThread();
159 ASSERT_TRUE(embedded_test_server()->Start()); 160 ASSERT_TRUE(embedded_test_server()->Start());
161
162 // Make sure app banners are disabled in the browser so they do not
163 // interfere with the test.
164 feature_list_.InitAndDisableFeature(features::kAppBanners);
160 } 165 }
161 166
162 // Returns a test server URL to a page controlled by a service worker with 167 // Returns a test server URL to a page controlled by a service worker with
163 // |manifest_url| injected as the manifest tag. 168 // |manifest_url| injected as the manifest tag.
164 std::string GetURLOfPageWithServiceWorkerAndManifest( 169 std::string GetURLOfPageWithServiceWorkerAndManifest(
165 const std::string& manifest_url) { 170 const std::string& manifest_url) {
166 return "/banners/manifest_test_page.html?manifest=" + 171 return "/banners/manifest_test_page.html?manifest=" +
167 embedded_test_server()->GetURL(manifest_url).spec(); 172 embedded_test_server()->GetURL(manifest_url).spec();
168 } 173 }
169 174
170 void NavigateAndRunInstallableManager(CallbackTester* tester, 175 void NavigateAndRunInstallableManager(CallbackTester* tester,
171 const InstallableParams& params, 176 const InstallableParams& params,
172 const std::string& url) { 177 const std::string& url) {
173 GURL test_url = embedded_test_server()->GetURL(url); 178 GURL test_url = embedded_test_server()->GetURL(url);
174 ui_test_utils::NavigateToURL(browser(), test_url); 179 ui_test_utils::NavigateToURL(browser(), test_url);
175 RunInstallableManager(tester, params); 180 RunInstallableManager(tester, params);
176 } 181 }
177 182
178 void RunInstallableManager(CallbackTester* tester, 183 void RunInstallableManager(CallbackTester* tester,
179 const InstallableParams& params) { 184 const InstallableParams& params) {
180 InstallableManager* manager = GetManager(); 185 InstallableManager* manager = GetManager();
181 manager->GetData(params, 186 manager->GetData(params,
182 base::Bind(&CallbackTester::OnDidFinishInstallableCheck, 187 base::Bind(&CallbackTester::OnDidFinishInstallableCheck,
183 base::Unretained(tester))); 188 base::Unretained(tester)));
184 } 189 }
185 190
186 void SetUpCommandLine(base::CommandLine* command_line) override {
187 // Make sure app banners are disabled in the browser so they do not
188 // interfere with the test.
189 command_line->AppendSwitch(switches::kDisableAddToShelf);
190 }
191
192 InstallableManager* GetManager() { 191 InstallableManager* GetManager() {
193 content::WebContents* web_contents = 192 content::WebContents* web_contents =
194 browser()->tab_strip_model()->GetActiveWebContents(); 193 browser()->tab_strip_model()->GetActiveWebContents();
195 InstallableManager::CreateForWebContents(web_contents); 194 InstallableManager::CreateForWebContents(web_contents);
196 InstallableManager* manager = 195 InstallableManager* manager =
197 InstallableManager::FromWebContents(web_contents); 196 InstallableManager::FromWebContents(web_contents);
198 CHECK(manager); 197 CHECK(manager);
199 198
200 return manager; 199 return manager;
201 } 200 }
202 201
203 InstallabilityCheckStatus GetStatus() { return GetManager()->page_status_; } 202 InstallabilityCheckStatus GetStatus() { return GetManager()->page_status_; }
203
204 private:
205 base::test::ScopedFeatureList feature_list_;
204 }; 206 };
205 207
206 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest, 208 IN_PROC_BROWSER_TEST_F(InstallableManagerBrowserTest,
207 ManagerBeginsInEmptyState) { 209 ManagerBeginsInEmptyState) {
208 // Ensure that the InstallableManager starts off with everything null. 210 // Ensure that the InstallableManager starts off with everything null.
209 InstallableManager* manager = GetManager(); 211 InstallableManager* manager = GetManager();
210 212
211 EXPECT_TRUE(manager->manifest().IsEmpty()); 213 EXPECT_TRUE(manager->manifest().IsEmpty());
212 EXPECT_TRUE(manager->manifest_url().is_empty()); 214 EXPECT_TRUE(manager->manifest_url().is_empty());
213 EXPECT_TRUE(manager->icons_.empty()); 215 EXPECT_TRUE(manager->icons_.empty());
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 CheckNestedCallsToGetData) { 843 CheckNestedCallsToGetData) {
842 // Verify that we can call GetData while in a callback from GetData. 844 // Verify that we can call GetData while in a callback from GetData.
843 base::RunLoop run_loop; 845 base::RunLoop run_loop;
844 InstallableParams params = GetWebAppParams(); 846 InstallableParams params = GetWebAppParams();
845 std::unique_ptr<NestedCallbackTester> tester( 847 std::unique_ptr<NestedCallbackTester> tester(
846 new NestedCallbackTester(GetManager(), params, run_loop.QuitClosure())); 848 new NestedCallbackTester(GetManager(), params, run_loop.QuitClosure()));
847 849
848 tester->Run(); 850 tester->Run();
849 run_loop.Run(); 851 run_loop.Run();
850 } 852 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698