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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
7 #include "components/autofill/core/common/autofill_switches.h"
8 #include "content/public/common/content_switches.h"
9 #include "testing/gtest/include/gtest/gtest.h"
15 TEST(WalletServiceSandboxUrl, CheckSandboxUrls) {
16 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
17 switches::kWalletServiceUseSandbox, "1");
19 EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
20 "autocheckout/v1/getWalletItemsJwtless",
21 GetGetWalletItemsUrl(1).spec());
22 EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/1/"
23 "autocheckout/v1/getFullWalletJwtless?s7e=otp",
24 GetGetFullWalletUrl(1).spec());
25 EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/paymentMethods",
26 GetManageInstrumentsUrl(1).spec());
27 EXPECT_EQ("https://wallet-web.sandbox.google.com/manage/w/1/settings/"
29 GetManageAddressesUrl(1).spec());
30 EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
31 "autocheckout/v1/acceptLegalDocument",
32 GetAcceptLegalDocumentsUrl(1).spec());
33 EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/2/"
34 "autocheckout/v1/authenticateInstrument?s7e=cvn",
35 GetAuthenticateInstrumentUrl(2).spec());
36 EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/wallet/"
37 "autocheckout/v1/saveToWallet",
38 GetSaveToWalletNoEscrowUrl(1).spec());
39 EXPECT_EQ("https://wallet-web.sandbox.google.com/online-secure/v2/u/1/"
40 "autocheckout/v1/saveToWallet?s7e=card_number%3Bcvn",
41 GetSaveToWalletUrl(1).spec());
42 EXPECT_EQ("https://wallet-web.sandbox.google.com/online/v2/u/1/"
43 "passiveauth?isChromePayments=true",
44 GetPassiveAuthUrl(1).spec());
47 TEST(WalletServiceSandboxUrl, CheckProdUrls) {
48 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
49 switches::kWalletServiceUseSandbox, "0");
51 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
52 "autocheckout/v1/getWalletItemsJwtless",
53 GetGetWalletItemsUrl(1).spec());
54 EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/1/"
55 "autocheckout/v1/getFullWalletJwtless?s7e=otp",
56 GetGetFullWalletUrl(1).spec());
57 EXPECT_EQ("https://wallet.google.com/manage/w/1/paymentMethods",
58 GetManageInstrumentsUrl(1).spec());
59 EXPECT_EQ("https://wallet.google.com/manage/w/1/settings/addresses",
60 GetManageAddressesUrl(1).spec());
61 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
62 "autocheckout/v1/acceptLegalDocument",
63 GetAcceptLegalDocumentsUrl(1).spec());
64 EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/4/"
65 "autocheckout/v1/authenticateInstrument?s7e=cvn",
66 GetAuthenticateInstrumentUrl(4).spec());
67 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/wallet/"
68 "autocheckout/v1/saveToWallet",
69 GetSaveToWalletNoEscrowUrl(1).spec());
70 EXPECT_EQ("https://wallet.google.com/online-secure/v2/u/1/"
71 "autocheckout/v1/saveToWallet?s7e=card_number%3Bcvn",
72 GetSaveToWalletUrl(1).spec());
73 EXPECT_EQ("https://wallet.google.com/online/v2/u/1/"
74 "passiveauth?isChromePayments=true",
75 GetPassiveAuthUrl(1).spec());
78 TEST(WalletServiceUrl, DefaultsToProd) {
79 #if defined(GOOGLE_CHROME_BUILD)
80 EXPECT_TRUE(IsUsingProd());
82 EXPECT_FALSE(IsUsingProd());
85 CommandLine* command_line = CommandLine::ForCurrentProcess();
86 command_line->AppendSwitch(::switches::kReduceSecurityForTesting);
87 EXPECT_FALSE(IsUsingProd());
89 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "0");
90 EXPECT_TRUE(IsUsingProd());
93 TEST(WalletServiceUrl, IsUsingProd) {
94 CommandLine* command_line = CommandLine::ForCurrentProcess();
95 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1");
96 EXPECT_FALSE(IsUsingProd());
98 const GURL sandbox_get_items_url = GetGetWalletItemsUrl(0);
99 const GURL fake_service_url = GURL("http://goo.gl");
100 command_line->AppendSwitchASCII(switches::kWalletServiceUrl,
101 fake_service_url.spec());
103 const GURL flag_get_items_url = GetGetWalletItemsUrl(0);
104 EXPECT_NE(sandbox_get_items_url, flag_get_items_url);
105 EXPECT_EQ(fake_service_url.GetOrigin(), flag_get_items_url.GetOrigin());
108 TEST(WalletServiceUrl, IsSignInContinueUrl) {
109 EXPECT_TRUE(GetSignInContinueUrl().SchemeIsSecure());
111 CommandLine* command_line = CommandLine::ForCurrentProcess();
112 command_line->AppendSwitchASCII(switches::kWalletServiceUseSandbox, "1");
114 // authuser query param is respected.
115 const char sign_in_url[] = "https://wallet-web.sandbox.google.com/online/v2/"
116 "u/0/passiveauth?isChromePayments=true&authuser=4";
117 size_t user_index = 100;
118 EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url), &user_index));
119 EXPECT_EQ(4U, user_index);
121 // No authuser query param means 0 is assumed.
123 const char sign_in_url_no_user[] = "https://wallet-web.sandbox.google.com/"
124 "online/v2/u/0/passiveauth?isChromePayments=true";
125 EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_no_user), &user_index));
126 EXPECT_EQ(0U, user_index);
128 // A authuser query param that doesn't parse means 0 is assumed.
130 const char sign_in_url_bad_user[] = "https://wallet-web.sandbox.google.com/"
131 "online/v2/u/0/passiveauth?isChromePayments=true&authuser=yolo";
132 EXPECT_TRUE(IsSignInContinueUrl(GURL(sign_in_url_bad_user), &user_index));
133 EXPECT_EQ(0U, user_index);
135 const char not_a_sign_in_url[] = "https://wallet-web.sandbox.google.com/"
136 "online/v2/u/0/example";
137 EXPECT_FALSE(IsSignInContinueUrl(GURL(not_a_sign_in_url), &user_index));
140 TEST(WalletServiceUrl, IsSignInRelatedUrl) {
141 EXPECT_TRUE(IsSignInRelatedUrl(GetSignInUrl()));
142 EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.youtube.com")));
143 EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.youtube.com/")));
144 EXPECT_TRUE(IsSignInRelatedUrl(GURL("https://accounts.google.com")));
145 EXPECT_FALSE(IsSignInRelatedUrl(GURL("http://google.com")));
148 } // namespace wallet
149 } // namespace autofill