OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/autofill/content/browser/risk/fingerprint.h" | 5 #include "components/autofill/content/browser/risk/fingerprint.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/test/scoped_task_environment.h" | |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" | 16 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" |
16 #include "content/public/browser/gpu_data_manager.h" | 17 #include "content/public/browser/gpu_data_manager.h" |
17 #include "content/public/common/screen_info.h" | 18 #include "content/public/common/screen_info.h" |
18 #include "content/public/test/content_browser_test.h" | 19 #include "content/public/test/content_browser_test.h" |
19 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
20 #include "device/geolocation/geolocation_provider.h" | 21 #include "device/geolocation/geolocation_provider.h" |
21 #include "device/geolocation/geoposition.h" | 22 #include "device/geolocation/geoposition.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 // should be serialized into the resulting protocol buffer. | 62 // should be serialized into the resulting protocol buffer. |
62 const double kLatitude = -42.0; | 63 const double kLatitude = -42.0; |
63 const double kLongitude = 17.3; | 64 const double kLongitude = 17.3; |
64 const double kAltitude = 123.4; | 65 const double kAltitude = 123.4; |
65 const double kAccuracy = 73.7; | 66 const double kAccuracy = 73.7; |
66 const int kGeolocationTime = 87; | 67 const int kGeolocationTime = 87; |
67 | 68 |
68 class AutofillRiskFingerprintTest : public content::ContentBrowserTest { | 69 class AutofillRiskFingerprintTest : public content::ContentBrowserTest { |
69 public: | 70 public: |
70 AutofillRiskFingerprintTest() | 71 AutofillRiskFingerprintTest() |
71 : window_bounds_(2, 3, 5, 7), | 72 : scoped_task_environment_( |
73 base::test::ScopedTaskEnvironment::MainThreadType::UI), | |
74 window_bounds_(2, 3, 5, 7), | |
72 content_bounds_(11, 13, 17, 37), | 75 content_bounds_(11, 13, 17, 37), |
73 screen_bounds_(0, 0, 101, 71), | 76 screen_bounds_(0, 0, 101, 71), |
74 available_screen_bounds_(0, 11, 101, 60), | 77 available_screen_bounds_(0, 11, 101, 60), |
75 unavailable_screen_bounds_(0, 0, 101, 11) {} | 78 unavailable_screen_bounds_(0, 0, 101, 11) {} |
76 | 79 |
77 void GetFingerprintTestCallback(std::unique_ptr<Fingerprint> fingerprint) { | 80 void GetFingerprintTestCallback(std::unique_ptr<Fingerprint> fingerprint) { |
78 // Verify that all fields Chrome can fill have been filled. | 81 // Verify that all fields Chrome can fill have been filled. |
79 ASSERT_TRUE(fingerprint->has_machine_characteristics()); | 82 ASSERT_TRUE(fingerprint->has_machine_characteristics()); |
80 const Fingerprint::MachineCharacteristics& machine = | 83 const Fingerprint::MachineCharacteristics& machine = |
81 fingerprint->machine_characteristics(); | 84 fingerprint->machine_characteristics(); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 transient_state.outer_window_size().width()); | 163 transient_state.outer_window_size().width()); |
161 EXPECT_EQ(window_bounds_.height(), | 164 EXPECT_EQ(window_bounds_.height(), |
162 transient_state.outer_window_size().height()); | 165 transient_state.outer_window_size().height()); |
163 EXPECT_EQ(kObfuscatedGaiaId, fingerprint->metadata().obfuscated_gaia_id()); | 166 EXPECT_EQ(kObfuscatedGaiaId, fingerprint->metadata().obfuscated_gaia_id()); |
164 EXPECT_EQ(kAltitude, location.altitude()); | 167 EXPECT_EQ(kAltitude, location.altitude()); |
165 EXPECT_EQ(kLatitude, location.latitude()); | 168 EXPECT_EQ(kLatitude, location.latitude()); |
166 EXPECT_EQ(kLongitude, location.longitude()); | 169 EXPECT_EQ(kLongitude, location.longitude()); |
167 EXPECT_EQ(kAccuracy, location.accuracy()); | 170 EXPECT_EQ(kAccuracy, location.accuracy()); |
168 EXPECT_EQ(kGeolocationTime, location.time_in_ms()); | 171 EXPECT_EQ(kGeolocationTime, location.time_in_ms()); |
169 | 172 |
170 message_loop_.QuitWhenIdle(); | 173 base::MessageLoop::current()->QuitWhenIdle(); |
sdefresne
2017/04/28 10:00:23
Shouldn't this use base::RunLoop().RunUntilIdle()?
fdoray
2017/05/01 17:16:50
Removed this file from this CL since it requires n
| |
171 } | 174 } |
172 | 175 |
173 protected: | 176 protected: |
177 base::test::ScopedTaskEnvironment scoped_task_environment_; | |
178 | |
174 // Constants defining bounds in the screen coordinate system that are passed | 179 // Constants defining bounds in the screen coordinate system that are passed |
175 // verbatim to the fingerprinter code and should be serialized into the | 180 // verbatim to the fingerprinter code and should be serialized into the |
176 // resulting protocol buffer. Declared as class members because gfx::Rect is | 181 // resulting protocol buffer. Declared as class members because gfx::Rect is |
177 // not a POD type, so it cannot be statically initialized. | 182 // not a POD type, so it cannot be statically initialized. |
178 const gfx::Rect window_bounds_; | 183 const gfx::Rect window_bounds_; |
179 const gfx::Rect content_bounds_; | 184 const gfx::Rect content_bounds_; |
180 const gfx::Rect screen_bounds_; | 185 const gfx::Rect screen_bounds_; |
181 const gfx::Rect available_screen_bounds_; | 186 const gfx::Rect available_screen_bounds_; |
182 const gfx::Rect unavailable_screen_bounds_; | 187 const gfx::Rect unavailable_screen_bounds_; |
183 | |
184 // A message loop to block on the asynchronous loading of the fingerprint. | |
185 base::MessageLoopForUI message_loop_; | |
186 }; | 188 }; |
187 | 189 |
188 // Test that getting a fingerprint works on some basic level. | 190 // Test that getting a fingerprint works on some basic level. |
189 IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, GetFingerprint) { | 191 IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, GetFingerprint) { |
190 device::Geoposition position; | 192 device::Geoposition position; |
191 position.latitude = kLatitude; | 193 position.latitude = kLatitude; |
192 position.longitude = kLongitude; | 194 position.longitude = kLongitude; |
193 position.altitude = kAltitude; | 195 position.altitude = kAltitude; |
194 position.accuracy = kAccuracy; | 196 position.accuracy = kAccuracy; |
195 position.timestamp = | 197 position.timestamp = |
(...skipping 14 matching lines...) Expand all Loading... | |
210 base::TimeDelta::FromDays(1), // Ought to be longer than any test run. | 212 base::TimeDelta::FromDays(1), // Ought to be longer than any test run. |
211 base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback, | 213 base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback, |
212 base::Unretained(this))); | 214 base::Unretained(this))); |
213 | 215 |
214 // Wait for the callback to be called. | 216 // Wait for the callback to be called. |
215 base::RunLoop().Run(); | 217 base::RunLoop().Run(); |
216 } | 218 } |
217 | 219 |
218 } // namespace risk | 220 } // namespace risk |
219 } // namespace autofill | 221 } // namespace autofill |
OLD | NEW |