OLD | NEW |
---|---|
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 "base/bind_helpers.h" | 5 #include "base/bind_helpers.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "chrome/browser/budget_service/budget_manager.h" | 9 #include "chrome/browser/budget_service/budget_manager.h" |
10 #include "chrome/browser/budget_service/budget_manager_factory.h" | 10 #include "chrome/browser/budget_service/budget_manager_factory.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 private: | 87 private: |
88 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 88 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
89 // Lifetime of the BudgetManager is tied to the profile of the test. | 89 // Lifetime of the BudgetManager is tied to the profile of the test. |
90 BudgetManager* budget_manager_ = nullptr; | 90 BudgetManager* budget_manager_ = nullptr; |
91 bool success_ = false; | 91 bool success_ = false; |
92 }; | 92 }; |
93 | 93 |
94 IN_PROC_BROWSER_TEST_F(BudgetManagerBrowserTest, BudgetInDocument) { | 94 IN_PROC_BROWSER_TEST_F(BudgetManagerBrowserTest, BudgetInDocument) { |
95 std::string script_result; | 95 std::string script_result; |
96 | 96 |
97 // The page will have been loaded once, which gives a budget of 3. | 97 LoadTestPage(); // Reload to build site engagement. |
98 | |
99 // The page will have been loaded twice, which gives a budget of 2. | |
98 ASSERT_TRUE(RunScript("documentGetBudget()", &script_result)); | 100 ASSERT_TRUE(RunScript("documentGetBudget()", &script_result)); |
99 ASSERT_EQ("ok - budget returned value of 3", script_result); | 101 EXPECT_EQ("ok - budget returned value of 2", script_result); |
100 | 102 |
101 ASSERT_TRUE(RunScript("documentReserveBudget()", &script_result)); | 103 ASSERT_TRUE(RunScript("documentReserveBudget()", &script_result)); |
102 ASSERT_EQ("ok - reserved budget", script_result); | 104 EXPECT_EQ("ok - reserved budget", script_result); |
103 | 105 |
104 // After reserving budget, the new budget should be at 1. | 106 // After reserving budget, the new budget should be at 0. |
105 ASSERT_TRUE(RunScript("documentGetBudget()", &script_result)); | 107 ASSERT_TRUE(RunScript("documentGetBudget()", &script_result)); |
106 ASSERT_EQ("ok - budget returned value of 1", script_result); | 108 EXPECT_EQ("ok - budget returned value of 0", script_result); |
107 | 109 |
108 // A second reserve should fail because there is not enough budget. | 110 // A second reserve should fail because there is not enough budget. |
109 ASSERT_TRUE(RunScript("documentReserveBudget()", &script_result)); | 111 ASSERT_TRUE(RunScript("documentReserveBudget()", &script_result)); |
110 ASSERT_EQ("failed - not able to reserve budget", script_result); | 112 EXPECT_EQ("failed - not able to reserve budget", script_result); |
111 | 113 |
112 // Consume should succeed because there is an existing reservation. | 114 // Consume should succeed because there is an existing reservation. |
113 ConsumeReservation(); | 115 ConsumeReservation(); |
114 ASSERT_TRUE(success()); | 116 ASSERT_TRUE(success()); |
115 | 117 |
116 // Second consume should fail because the reservation is consumed. | 118 // Second consume should fail because the reservation is consumed. |
117 ConsumeReservation(); | 119 ConsumeReservation(); |
118 ASSERT_FALSE(success()); | 120 ASSERT_FALSE(success()); |
119 } | 121 } |
120 | 122 |
121 IN_PROC_BROWSER_TEST_F(BudgetManagerBrowserTest, BudgetInWorker) { | 123 IN_PROC_BROWSER_TEST_F(BudgetManagerBrowserTest, BudgetInWorker) { |
122 std::string script_result; | 124 std::string script_result; |
123 | 125 |
124 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 126 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
125 ASSERT_EQ("ok - service worker registered", script_result); | 127 EXPECT_EQ("ok - service worker registered", script_result); |
126 | 128 |
127 LoadTestPage(); // Reload to become controlled. | 129 LoadTestPage(); // Reload to become controlled. |
130 LoadTestPage(); // Reload to build site engagement. | |
131 LoadTestPage(); // Reload to build site engagement. | |
132 LoadTestPage(); // Reload to build site engagement. | |
133 LoadTestPage(); // Reload to build site engagement. | |
Peter Beverloo
2017/01/12 14:40:04
This will likely contribute to making this test fl
harkness
2017/01/12 17:44:15
I don't know of a way to do it. Browser tests are
Peter Beverloo
2017/01/12 17:49:41
Probably, but that will also need a fair bit of pl
harkness
2017/01/13 11:54:45
Done!
| |
128 | 134 |
129 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 135 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
130 ASSERT_EQ("true - is controlled", script_result); | 136 EXPECT_EQ("true - is controlled", script_result); |
Peter Beverloo
2017/01/12 14:40:04
This should be an ASSERT.
We use ASSERT_* when it
harkness
2017/01/12 17:44:15
Done.
| |
131 | 137 |
132 // The page will have been loaded twice and a service worker was registered, | 138 // The page will have been loaded five times, giving a budget of 5. |
133 // which gives a budget of 4.5. | |
134 ASSERT_TRUE(RunScript("workerGetBudget()", &script_result)); | 139 ASSERT_TRUE(RunScript("workerGetBudget()", &script_result)); |
135 ASSERT_EQ("ok - budget returned value of 4.5", script_result); | 140 EXPECT_EQ("ok - budget returned value of 5", script_result); |
136 | 141 |
137 // With a budget of 4.5, two reservations should succeed. | 142 // With a budget of 5, two reservations should succeed. |
138 ASSERT_TRUE(RunScript("workerReserveBudget()", &script_result)); | 143 ASSERT_TRUE(RunScript("workerReserveBudget()", &script_result)); |
139 ASSERT_EQ("ok - reserved budget", script_result); | 144 EXPECT_EQ("ok - reserved budget", script_result); |
140 | 145 |
141 ASSERT_TRUE(RunScript("workerReserveBudget()", &script_result)); | 146 ASSERT_TRUE(RunScript("workerReserveBudget()", &script_result)); |
142 ASSERT_EQ("ok - reserved budget", script_result); | 147 EXPECT_EQ("ok - reserved budget", script_result); |
143 | 148 |
144 // After reserving budget, the new budget should be at 0.5. | 149 // After reserving budget, the new budget should be at 1. |
145 ASSERT_TRUE(RunScript("workerGetBudget()", &script_result)); | 150 ASSERT_TRUE(RunScript("workerGetBudget()", &script_result)); |
146 ASSERT_EQ("ok - budget returned value of 0.5", script_result); | 151 EXPECT_EQ("ok - budget returned value of 1", script_result); |
147 | 152 |
148 // A second reserve should fail because there is not enough budget. | 153 // A second reserve should fail because there is not enough budget. |
149 ASSERT_TRUE(RunScript("workerReserveBudget()", &script_result)); | 154 ASSERT_TRUE(RunScript("workerReserveBudget()", &script_result)); |
150 ASSERT_EQ("failed - not able to reserve budget", script_result); | 155 EXPECT_EQ("failed - not able to reserve budget", script_result); |
151 | 156 |
152 // Two consumes should succeed because there are existing reservations. | 157 // Two consumes should succeed because there are existing reservations. |
153 ConsumeReservation(); | 158 ConsumeReservation(); |
154 ASSERT_TRUE(success()); | 159 ASSERT_TRUE(success()); |
155 | 160 |
156 ConsumeReservation(); | 161 ConsumeReservation(); |
157 ASSERT_TRUE(success()); | 162 ASSERT_TRUE(success()); |
158 | 163 |
159 // One more consume should fail, because all reservations are consumed. | 164 // One more consume should fail, because all reservations are consumed. |
160 ConsumeReservation(); | 165 ConsumeReservation(); |
161 ASSERT_FALSE(success()); | 166 ASSERT_FALSE(success()); |
162 } | 167 } |
163 | 168 |
164 } // namespace | 169 } // namespace |
OLD | NEW |