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

Side by Side Diff: components/autofill/content/browser/wallet/wallet_service_url_unittest.cc

Issue 1288093004: rAc Wallet extirpation round 4: clean out RPC code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gn Created 5 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "components/autofill/content/browser/wallet/wallet_service_url.h" 6 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
7 #include "components/autofill/core/common/autofill_switches.h" 7 #include "components/autofill/core/common/autofill_switches.h"
8 #include "content/public/common/content_switches.h" 8 #include "content/public/common/content_switches.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "url/gurl.h" 10 #include "url/gurl.h"
11 11
12 namespace autofill { 12 namespace autofill {
13 namespace wallet { 13 namespace wallet {
14 14
15 namespace {
16
17 bool IsUsingProd() {
18 return GetManageAddressesUrl(1).GetWithEmptyPath() ==
19 GURL("https://wallet.google.com/");
20 }
21 }
22
15 TEST(WalletServiceSandboxUrl, CheckSandboxUrls) { 23 TEST(WalletServiceSandboxUrl, CheckSandboxUrls) {
16 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 24 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
17 switches::kWalletServiceUseSandbox, "1"); 25 switches::kWalletServiceUseSandbox, "1");
18 26
19 EXPECT_EQ(
20 "https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
21 "autocheckout/v1/getWalletItemsJwtless",
22 GetGetWalletItemsUrl(1).spec());
23 EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/1/"
24 "autocheckout/v1/getFullWalletJwtless?s7e=otp",
25 GetGetFullWalletUrl(1).spec());
26 EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/paymentMethods", 27 EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/paymentMethods",
27 GetManageInstrumentsUrl(1).spec()); 28 GetManageInstrumentsUrl(1).spec());
28 EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/settings/" 29 EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/settings/"
29 "addresses", 30 "addresses",
30 GetManageAddressesUrl(1).spec()); 31 GetManageAddressesUrl(1).spec());
31 EXPECT_EQ(
32 "https://wallet-web.sandbox.google.com/"
33 "legaldocument?family=0.privacynotice",
34 GetPrivacyNoticeUrl().spec());
35 EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
36 "autocheckout/v1/acceptLegalDocument",
37 GetAcceptLegalDocumentsUrl(1).spec());
38 EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/2/"
39 "autocheckout/v1/authenticateInstrument?s7e=cvn",
40 GetAuthenticateInstrumentUrl(2).spec());
41 EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
42 "autocheckout/v1/saveToWallet",
43 GetSaveToWalletNoEscrowUrl(1).spec());
44 EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/1/"
45 "autocheckout/v1/saveToWallet?s7e=card_number%3Bcvn",
46 GetSaveToWalletUrl(1).spec());
47 EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/"
48 "passiveauth?isChromePayments=true",
49 GetPassiveAuthUrl(1).spec());
50 } 32 }
51 33
52 TEST(WalletServiceSandboxUrl, CheckProdUrls) { 34 TEST(WalletServiceSandboxUrl, CheckProdUrls) {
53 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 35 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
54 switches::kWalletServiceUseSandbox, "0"); 36 switches::kWalletServiceUseSandbox, "0");
55 37
56 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
57 "autocheckout/v1/getWalletItemsJwtless",
58 GetGetWalletItemsUrl(1).spec());
59 EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/1/"
60 "autocheckout/v1/getFullWalletJwtless?s7e=otp",
61 GetGetFullWalletUrl(1).spec());
62 EXPECT_EQ("https://wallet.google.com/manage/w/1/paymentMethods", 38 EXPECT_EQ("https://wallet.google.com/manage/w/1/paymentMethods",
63 GetManageInstrumentsUrl(1).spec()); 39 GetManageInstrumentsUrl(1).spec());
64 EXPECT_EQ("https://wallet.google.com/manage/w/1/settings/addresses", 40 EXPECT_EQ("https://wallet.google.com/manage/w/1/settings/addresses",
65 GetManageAddressesUrl(1).spec()); 41 GetManageAddressesUrl(1).spec());
66 EXPECT_EQ(
67 "https://wallet.google.com/"
68 "legaldocument?family=0.privacynotice",
69 GetPrivacyNoticeUrl().spec());
70 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
71 "autocheckout/v1/acceptLegalDocument",
72 GetAcceptLegalDocumentsUrl(1).spec());
73 EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/4/"
74 "autocheckout/v1/authenticateInstrument?s7e=cvn",
75 GetAuthenticateInstrumentUrl(4).spec());
76 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
77 "autocheckout/v1/saveToWallet",
78 GetSaveToWalletNoEscrowUrl(1).spec());
79 EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/1/"
80 "autocheckout/v1/saveToWallet?s7e=card_number%3Bcvn",
81 GetSaveToWalletUrl(1).spec());
82 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/"
83 "passiveauth?isChromePayments=true",
84 GetPassiveAuthUrl(1).spec());
85 } 42 }
86 43
87 TEST(WalletServiceUrl, DefaultsToProd) { 44 TEST(WalletServiceUrl, DefaultsToProd) {
88 #if defined(ENABLE_PROD_WALLET_SERVICE) 45 #if defined(ENABLE_PROD_WALLET_SERVICE)
89 EXPECT_TRUE(IsUsingProd()); 46 EXPECT_TRUE(IsUsingProd());
90 #else 47 #else
91 EXPECT_FALSE(IsUsingProd()); 48 EXPECT_FALSE(IsUsingProd());
92 #endif 49 #endif
93 50
94 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 51 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
95 command_line->AppendSwitch(::switches::kReduceSecurityForTesting); 52 command_line->AppendSwitch(::switches::kReduceSecurityForTesting);
96 EXPECT_FALSE(IsUsingProd()); 53 EXPECT_FALSE(IsUsingProd());
97 54
98 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "0"); 55 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "0");
99 EXPECT_TRUE(IsUsingProd()); 56 EXPECT_TRUE(IsUsingProd());
100 } 57 }
101 58
102 TEST(WalletServiceUrl, IsUsingProd) { 59 TEST(WalletServiceUrl, IsUsingProd) {
103 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 60 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
104 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1"); 61 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1");
105 EXPECT_FALSE(IsUsingProd()); 62 EXPECT_FALSE(IsUsingProd());
106
107 const GURL sandbox_get_items_url = GetGetWalletItemsUrl(0);
108 const GURL fake_service_url = GURL("http://goo.gl");
109 command_line->AppendSwitchASCII(switches::kWalletServiceUrl,
110 fake_service_url.spec());
111
112 const GURL flag_get_items_url = GetGetWalletItemsUrl(0);
113 EXPECT_NE(sandbox_get_items_url, flag_get_items_url);
114 EXPECT_EQ(fake_service_url.GetOrigin(), flag_get_items_url.GetOrigin());
115 }
116
117 TEST(WalletServiceUrl, IsSignInContinueUrl) {
118 EXPECT_TRUE(GetSignInContinueUrl().SchemeIsCryptographic());
119
120 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
121 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1");
122
123 // authuser query param is respected.
124 const char sign_in_url[] = "https://wallet-web.sandbox.google.com/online/v2/"
125 "u/0/passiveauth?isChromePayments=true&authuser=4";
126 size_t user_index = 100;
127 EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url), &user_index));
128 EXPECT_EQ(4U, user_index);
129
130 // No authuser query param means 0 is assumed.
131 user_index = 101;
132 const char sign_in_url_no_user[] = "https://wallet-web.sandbox.google.com/"
133 "online/v2/u/0/passiveauth?isChromePayments=true";
134 EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_no_user), &user_index));
135 EXPECT_EQ(0U, user_index);
136
137 // A authuser query param that doesn't parse means 0 is assumed.
138 user_index = 102;
139 const char sign_in_url_bad_user[] = "https://wallet-web.sandbox.google.com/"
140 "online/v2/u/0/passiveauth?isChromePayments=true&authuser=yolo";
141 EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_bad_user), &user_index));
142 EXPECT_EQ(0U, user_index);
143
144 const char not_a_sign_in_url[] = "https://wallet-web.sandbox.google.com/"
145 "online/v2/u/0/example";
146 EXPECT_FALSE(IsSignInContinueUrl(GURL(not_a_sign_in_url), &user_index));
147 }
148
149 TEST(WalletServiceUrl, IsSignInRelatedUrl) {
150 EXPECT_TRUE(IsSignInRelatedUrl(GetSignInUrl(0)));
151 EXPECT_TRUE(IsSignInRelatedUrl(GetAddAccountUrl()));
152 EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.youtube.com")));
153 EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.youtube.com/")));
154 EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.google.com")));
155 EXPECT_FALSE(IsSignInRelatedUrl(GURL("http://google.com")));
156 } 63 }
157 64
158 } // namespace wallet 65 } // namespace wallet
159 } // namespace autofill 66 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698