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

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

Issue 2942513002: Allow banners to trigger on sites which don't register a service worker onload. (Closed)
Patch Set: Don't cache NO_MATCHING_SERVICE_WORKER 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/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/public/platform/WebDisplayMode.h" 9 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
10 10
11 using IconPurpose = content::Manifest::Icon::IconPurpose; 11 using IconPurpose = content::Manifest::Icon::IconPurpose;
12 12
13 class InstallableManagerUnitTest : public testing::Test { 13 class InstallableManagerUnitTest : public testing::Test {
14 public: 14 public:
15 InstallableManagerUnitTest() : manager_(new InstallableManager(nullptr)) { } 15 InstallableManagerUnitTest()
16 : manager_(base::MakeUnique<InstallableManager>(nullptr)) {}
16 17
17 protected: 18 protected:
18 static base::NullableString16 ToNullableUTF16(const std::string& str) { 19 static base::NullableString16 ToNullableUTF16(const std::string& str) {
19 return base::NullableString16(base::UTF8ToUTF16(str), false); 20 return base::NullableString16(base::UTF8ToUTF16(str), false);
20 } 21 }
21 22
22 static content::Manifest GetValidManifest() { 23 static content::Manifest GetValidManifest() {
23 content::Manifest manifest; 24 content::Manifest manifest;
24 manifest.name = ToNullableUTF16("foo"); 25 manifest.name = ToNullableUTF16("foo");
25 manifest.short_name = ToNullableUTF16("bar"); 26 manifest.short_name = ToNullableUTF16("bar");
26 manifest.start_url = GURL("http://example.com"); 27 manifest.start_url = GURL("http://example.com");
27 manifest.display = blink::kWebDisplayModeStandalone; 28 manifest.display = blink::kWebDisplayModeStandalone;
28 29
29 content::Manifest::Icon primary_icon; 30 content::Manifest::Icon primary_icon;
30 primary_icon.type = base::ASCIIToUTF16("image/png"); 31 primary_icon.type = base::ASCIIToUTF16("image/png");
31 primary_icon.sizes.push_back(gfx::Size(144, 144)); 32 primary_icon.sizes.push_back(gfx::Size(144, 144));
32 primary_icon.purpose.push_back(IconPurpose::ANY); 33 primary_icon.purpose.push_back(IconPurpose::ANY);
33 manifest.icons.push_back(primary_icon); 34 manifest.icons.push_back(primary_icon);
34 35
35 // No need to include the optional badge icon as it does not affect the 36 // No need to include the optional badge icon as it does not affect the
36 // unit tests. 37 // unit tests.
37 return manifest; 38 return manifest;
38 } 39 }
39 40
40 bool IsManifestValid(const content::Manifest& manifest) { 41 bool IsManifestValid(const content::Manifest& manifest) {
41 // Explicitly reset the error code before running the method. 42 // Explicitly reset the error code before running the method.
42 manager_->set_installable_error(NO_ERROR_DETECTED); 43 manager_->set_valid_manifest_error(NO_ERROR_DETECTED);
43 return manager_->IsManifestValidForWebApp(manifest); 44 return manager_->IsManifestValidForWebApp(manifest);
44 } 45 }
45 46
46 InstallableStatusCode GetErrorCode() { 47 InstallableStatusCode GetErrorCode() {
47 return manager_->installable_error(); 48 return manager_->valid_manifest_error();
48 } 49 }
49 50
50 private: 51 private:
51 std::unique_ptr<InstallableManager> manager_; 52 std::unique_ptr<InstallableManager> manager_;
52 }; 53 };
53 54
54 TEST_F(InstallableManagerUnitTest, EmptyManifestIsInvalid) { 55 TEST_F(InstallableManagerUnitTest, EmptyManifestIsInvalid) {
55 content::Manifest manifest; 56 content::Manifest manifest;
56 EXPECT_FALSE(IsManifestValid(manifest)); 57 EXPECT_FALSE(IsManifestValid(manifest));
57 EXPECT_EQ(MANIFEST_EMPTY, GetErrorCode()); 58 EXPECT_EQ(MANIFEST_EMPTY, GetErrorCode());
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode()); 200 EXPECT_EQ(MANIFEST_DISPLAY_NOT_SUPPORTED, GetErrorCode());
200 201
201 manifest.display = blink::kWebDisplayModeStandalone; 202 manifest.display = blink::kWebDisplayModeStandalone;
202 EXPECT_TRUE(IsManifestValid(manifest)); 203 EXPECT_TRUE(IsManifestValid(manifest));
203 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); 204 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
204 205
205 manifest.display = blink::kWebDisplayModeFullscreen; 206 manifest.display = blink::kWebDisplayModeFullscreen;
206 EXPECT_TRUE(IsManifestValid(manifest)); 207 EXPECT_TRUE(IsManifestValid(manifest));
207 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode()); 208 EXPECT_EQ(NO_ERROR_DETECTED, GetErrorCode());
208 } 209 }
OLDNEW
« no previous file with comments | « chrome/browser/installable/installable_manager_browsertest.cc ('k') | tools/metrics/histograms/enums.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698