12
12
#include " chrome/browser/content_settings/host_content_settings_map_factory.h"
13
13
#include " chrome/browser/interstitials/security_interstitial_page_test_utils.h"
14
14
#include " chrome/browser/profiles/profile.h"
15
- #include " chrome/browser/ssl/https_only_mode_upgrade_interceptor.h"
15
+ #include " chrome/browser/ssl/https_upgrades_interceptor.h"
16
+ #include " chrome/common/chrome_features.h"
16
17
#include " chrome/common/pref_names.h"
17
18
#include " chrome/test/base/chrome_test_utils.h"
18
19
#include " components/prefs/pref_service.h"
@@ -42,22 +43,36 @@ enum class PageResult { kHttp, kHttps, kInterstitial };
42
43
struct TestCase {
43
44
bool init_secure;
44
45
const char * domain;
46
+ const char * path;
45
47
ControlType control_type;
46
48
PageResult expected_result;
47
49
};
48
50
51
+ constexpr char kSimple [] = " /simple.html" ;
52
+ // Nonexistent page results in a 404:
53
+ constexpr char kNonexistent [] = " /nonexistent.html" ;
54
+
49
55
constexpr TestCase kTestCases [] = {
50
- {false , " insecure1.test" , ControlType::ALLOW, PageResult::kHttp },
51
- {false , " insecure2.test" , ControlType::BLOCK_THIRD_PARTY,
56
+ {false , " insecure1.test" , kSimple , ControlType::ALLOW, PageResult::kHttp },
57
+ {false , " insecure2.test" , kSimple , ControlType::BLOCK_THIRD_PARTY,
58
+ PageResult::kHttp },
59
+ {false , " insecure3.test" , kSimple , ControlType::BLOCK,
60
+ PageResult::kInterstitial },
61
+ {false , " broken1.test" , kNonexistent , ControlType::ALLOW,
62
+ PageResult::kHttp },
63
+ {false , " broken2.test" , kNonexistent , ControlType::BLOCK_THIRD_PARTY,
52
64
PageResult::kHttp },
53
- {false , " insecure3.test" , ControlType::BLOCK, PageResult::kInterstitial },
54
- {false , " upgradable1.test" , ControlType::ALLOW, PageResult::kHttp },
55
- {false , " upgradable2.test" , ControlType::BLOCK_THIRD_PARTY,
65
+ {false , " broken3.test" , kNonexistent , ControlType::BLOCK,
66
+ PageResult::kInterstitial },
67
+ {false , " upgradable1.test" , kSimple , ControlType::ALLOW, PageResult::kHttp },
68
+ {false , " upgradable2.test" , kSimple , ControlType::BLOCK_THIRD_PARTY,
56
69
PageResult::kHttps },
57
- {false , " upgradable3.test" , ControlType::BLOCK, PageResult::kHttps },
58
- {true , " secure1.test" , ControlType::ALLOW, PageResult::kHttps },
59
- {true , " secure2.test" , ControlType::BLOCK_THIRD_PARTY, PageResult::kHttps },
60
- {true , " secure3.test" , ControlType::BLOCK, PageResult::kHttps }};
70
+ {false , " upgradable3.test" , kSimple , ControlType::BLOCK,
71
+ PageResult::kHttps },
72
+ {true , " secure1.test" , kSimple , ControlType::ALLOW, PageResult::kHttps },
73
+ {true , " secure2.test" , kSimple , ControlType::BLOCK_THIRD_PARTY,
74
+ PageResult::kHttps },
75
+ {true , " secure3.test" , kSimple , ControlType::BLOCK, PageResult::kHttps }};
61
76
62
77
base::FilePath GetTestDataDir () {
63
78
return base::FilePath (FILE_PATH_LITERAL (" net/data/url_request_unittest" ));
@@ -71,7 +86,8 @@ class HttpsUpgradeBrowserTest : public PlatformBrowserTest {
71
86
~HttpsUpgradeBrowserTest () override = default ;
72
87
73
88
void SetUp () override {
74
- feature_list_.InitAndEnableFeature (kBraveHttpsByDefault );
89
+ feature_list_.InitWithFeatures (
90
+ {features::kHttpsFirstModeV2 , kBraveHttpsByDefault }, {});
75
91
PlatformBrowserTest::SetUp ();
76
92
}
77
93
@@ -102,10 +118,8 @@ class HttpsUpgradeBrowserTest : public PlatformBrowserTest {
102
118
ASSERT_TRUE (http_server_.Start ());
103
119
ASSERT_TRUE (https_server_.Start ());
104
120
105
- HttpsOnlyModeUpgradeInterceptor::SetHttpsPortForTesting (
106
- https_server ()->port ());
107
- HttpsOnlyModeUpgradeInterceptor::SetHttpPortForTesting (
108
- http_server ()->port ());
121
+ HttpsUpgradesInterceptor::SetHttpsPortForTesting (https_server ()->port ());
122
+ HttpsUpgradesInterceptor::SetHttpPortForTesting (http_server ()->port ());
109
123
}
110
124
111
125
void SetUpCommandLine (base::CommandLine* command_line) override {
@@ -138,15 +152,19 @@ class HttpsUpgradeBrowserTest : public PlatformBrowserTest {
138
152
<< " test_case.control_type: " << test_case.control_type );
139
153
GURL initial_url =
140
154
test_case.init_secure
141
- ? https_server ()->GetURL (test_case.domain , " /simple.html " )
142
- : http_server ()->GetURL (test_case.domain , " /simple.html " );
155
+ ? https_server ()->GetURL (test_case.domain , test_case. path )
156
+ : http_server ()->GetURL (test_case.domain , test_case. path );
143
157
brave_shields::SetBraveShieldsEnabled (ContentSettings (), shields_enabled,
144
158
initial_url, nullptr );
145
159
brave_shields::SetHttpsUpgradeControlType (
146
160
ContentSettings (), test_case.control_type ,
147
161
global_setting ? GURL () : initial_url,
148
162
g_browser_process->local_state ());
149
- AttemptToNavigateToURL (initial_url);
163
+ // Run navigation twice to ensure that the behavior doesn't
164
+ // change after first run.
165
+ for (int i = 0 ; i < 2 ; ++i) {
166
+ AttemptToNavigateToURL (initial_url);
167
+ }
150
168
return initial_url;
151
169
}
152
170
@@ -195,7 +213,7 @@ IN_PROC_BROWSER_TEST_F(HttpsUpgradeBrowserTest, CheckUpgrades) {
195
213
GURL final_url =
196
214
(test_case.expected_result == PageResult::kHttp ? http_server ()
197
215
: https_server ())
198
- ->GetURL (test_case.domain , " /simple.html " );
216
+ ->GetURL (test_case.domain , test_case. path );
199
217
EXPECT_EQ (final_url, Contents ()->GetLastCommittedURL ());
200
218
}
201
219
}
0 commit comments