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

Side by Side Diff: chrome/browser/autofill/risk/fingerprint_browsertest.cc

Issue 14619006: [Autofill] Add geolocation data to Risk fingerprint. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't use high accuracy for now Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | components/autofill/browser/risk/fingerprint.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/risk/fingerprint.h" 5 #include "components/autofill/browser/risk/fingerprint.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/port.h" 9 #include "base/port.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" 12 #include "components/autofill/browser/risk/proto/fingerprint.pb.h"
13 #include "content/public/browser/geolocation_provider.h"
14 #include "content/public/common/geoposition.h"
15 #include "content/public/test/test_utils.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebScreenInfo.h" 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebScreenInfo.h"
16 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
17 20
18 namespace autofill { 21 namespace autofill {
19 namespace risk { 22 namespace risk {
20 23
21 const int64 kGaiaId = GG_INT64_C(99194853094755497); 24 const int64 kGaiaId = GG_INT64_C(99194853094755497);
22 const char kCharset[] = "UTF-8"; 25 const char kCharset[] = "UTF-8";
23 const char kAcceptLanguages[] = "en-US,en"; 26 const char kAcceptLanguages[] = "en-US,en";
24 const int kScreenColorDepth = 53; 27 const int kScreenColorDepth = 53;
25 28
29 const double kLatitude = -42.0;
30 const double kLongitude = 17.3;
31 const double kAltitude = 123.4;
32 const double kAccuracy = 73.7;
33 const int kGeolocationTime = 87;
34
26 class AutofillRiskFingerprintTest : public InProcessBrowserTest { 35 class AutofillRiskFingerprintTest : public InProcessBrowserTest {
27 public: 36 public:
28 AutofillRiskFingerprintTest() 37 AutofillRiskFingerprintTest()
29 : kWindowBounds(2, 3, 5, 7), 38 : kWindowBounds(2, 3, 5, 7),
30 kContentBounds(11, 13, 17, 37), 39 kContentBounds(11, 13, 17, 37),
31 kScreenBounds(0, 0, 101, 71), 40 kScreenBounds(0, 0, 101, 71),
32 kAvailableScreenBounds(0, 11, 101, 60), 41 kAvailableScreenBounds(0, 11, 101, 60),
33 kUnavailableScreenBounds(0, 0, 101, 11), 42 kUnavailableScreenBounds(0, 0, 101, 11),
34 message_loop_(MessageLoop::TYPE_UI) {} 43 message_loop_(MessageLoop::TYPE_UI) {}
35 44
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 ASSERT_TRUE(fingerprint->has_transient_state()); 77 ASSERT_TRUE(fingerprint->has_transient_state());
69 const Fingerprint_TransientState& transient_state = 78 const Fingerprint_TransientState& transient_state =
70 fingerprint->transient_state(); 79 fingerprint->transient_state();
71 ASSERT_TRUE(transient_state.has_inner_window_size()); 80 ASSERT_TRUE(transient_state.has_inner_window_size());
72 ASSERT_TRUE(transient_state.has_outer_window_size()); 81 ASSERT_TRUE(transient_state.has_outer_window_size());
73 ASSERT_TRUE(transient_state.inner_window_size().has_width()); 82 ASSERT_TRUE(transient_state.inner_window_size().has_width());
74 ASSERT_TRUE(transient_state.inner_window_size().has_height()); 83 ASSERT_TRUE(transient_state.inner_window_size().has_height());
75 ASSERT_TRUE(transient_state.outer_window_size().has_width()); 84 ASSERT_TRUE(transient_state.outer_window_size().has_width());
76 ASSERT_TRUE(transient_state.outer_window_size().has_height()); 85 ASSERT_TRUE(transient_state.outer_window_size().has_height());
77 86
87 ASSERT_TRUE(fingerprint->has_user_characteristics());
88 const Fingerprint_UserCharacteristics& user_characteristics =
89 fingerprint->user_characteristics();
90 ASSERT_TRUE(user_characteristics.has_location());
91 const Fingerprint_UserCharacteristics_Location& location =
92 user_characteristics.location();
93 ASSERT_TRUE(location.has_altitude());
94 ASSERT_TRUE(location.has_latitude());
95 ASSERT_TRUE(location.has_longitude());
96 ASSERT_TRUE(location.has_accuracy());
97 ASSERT_TRUE(location.has_time_in_ms());
98
78 ASSERT_TRUE(fingerprint->has_metadata()); 99 ASSERT_TRUE(fingerprint->has_metadata());
79 ASSERT_TRUE(fingerprint->metadata().has_timestamp_ms()); 100 ASSERT_TRUE(fingerprint->metadata().has_timestamp_ms());
80 ASSERT_TRUE(fingerprint->metadata().has_gaia_id()); 101 ASSERT_TRUE(fingerprint->metadata().has_gaia_id());
81 ASSERT_TRUE(fingerprint->metadata().has_fingerprinter_version()); 102 ASSERT_TRUE(fingerprint->metadata().has_fingerprinter_version());
82 103
83 // Some values have exact known (mocked out) values: 104 // Some values have exact known (mocked out) values:
84 ASSERT_EQ(2, machine.requested_language_size()); 105 ASSERT_EQ(2, machine.requested_language_size());
85 EXPECT_EQ("en-US", machine.requested_language(0)); 106 EXPECT_EQ("en-US", machine.requested_language(0));
86 EXPECT_EQ("en", machine.requested_language(1)); 107 EXPECT_EQ("en", machine.requested_language(1));
87 EXPECT_EQ(kCharset, machine.charset()); 108 EXPECT_EQ(kCharset, machine.charset());
88 EXPECT_EQ(kScreenColorDepth, machine.screen_color_depth()); 109 EXPECT_EQ(kScreenColorDepth, machine.screen_color_depth());
89 EXPECT_EQ(kUnavailableScreenBounds.width(), 110 EXPECT_EQ(kUnavailableScreenBounds.width(),
90 machine.unavailable_screen_size().width()); 111 machine.unavailable_screen_size().width());
91 EXPECT_EQ(kUnavailableScreenBounds.height(), 112 EXPECT_EQ(kUnavailableScreenBounds.height(),
92 machine.unavailable_screen_size().height()); 113 machine.unavailable_screen_size().height());
93 EXPECT_EQ( 114 EXPECT_EQ(
94 Fingerprint_MachineCharacteristics_BrowserFeature_FEATURE_AUTOCHECKOUT, 115 Fingerprint_MachineCharacteristics_BrowserFeature_FEATURE_AUTOCHECKOUT,
95 machine.browser_feature()); 116 machine.browser_feature());
96 EXPECT_EQ(kContentBounds.width(), 117 EXPECT_EQ(kContentBounds.width(),
97 transient_state.inner_window_size().width()); 118 transient_state.inner_window_size().width());
98 EXPECT_EQ(kContentBounds.height(), 119 EXPECT_EQ(kContentBounds.height(),
99 transient_state.inner_window_size().height()); 120 transient_state.inner_window_size().height());
100 EXPECT_EQ(kWindowBounds.width(), 121 EXPECT_EQ(kWindowBounds.width(),
101 transient_state.outer_window_size().width()); 122 transient_state.outer_window_size().width());
102 EXPECT_EQ(kWindowBounds.height(), 123 EXPECT_EQ(kWindowBounds.height(),
103 transient_state.outer_window_size().height()); 124 transient_state.outer_window_size().height());
104 EXPECT_EQ(kGaiaId, fingerprint->metadata().gaia_id()); 125 EXPECT_EQ(kGaiaId, fingerprint->metadata().gaia_id());
126 EXPECT_EQ(kAltitude, location.altitude());
127 EXPECT_EQ(kLatitude, location.latitude());
128 EXPECT_EQ(kLongitude, location.longitude());
129 EXPECT_EQ(kAccuracy, location.accuracy());
130 EXPECT_EQ(kGeolocationTime, location.time_in_ms());
105 131
106 message_loop_.Quit(); 132 message_loop_.Quit();
107 } 133 }
108 134
109 protected: 135 protected:
110 const gfx::Rect kWindowBounds; 136 const gfx::Rect kWindowBounds;
111 const gfx::Rect kContentBounds; 137 const gfx::Rect kContentBounds;
112 const gfx::Rect kScreenBounds; 138 const gfx::Rect kScreenBounds;
113 const gfx::Rect kAvailableScreenBounds; 139 const gfx::Rect kAvailableScreenBounds;
114 const gfx::Rect kUnavailableScreenBounds; 140 const gfx::Rect kUnavailableScreenBounds;
115 MessageLoop message_loop_; 141 MessageLoop message_loop_;
116 }; 142 };
117 143
118 // This test is flaky on Windows. See http://crbug.com/178356. 144 // This test is flaky on Windows. See http://crbug.com/178356.
119 #if defined(OS_WIN) 145 #if defined(OS_WIN)
120 #define MAYBE_GetFingerprint DISABLED_GetFingerprint 146 #define MAYBE_GetFingerprint DISABLED_GetFingerprint
121 #else 147 #else
122 #define MAYBE_GetFingerprint GetFingerprint 148 #define MAYBE_GetFingerprint GetFingerprint
123 #endif 149 #endif
124 // Test that getting a fingerprint works on some basic level. 150 // Test that getting a fingerprint works on some basic level.
125 IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, MAYBE_GetFingerprint) { 151 IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, MAYBE_GetFingerprint) {
152 content::Geoposition position;
153 position.latitude = kLatitude;
154 position.longitude = kLongitude;
155 position.altitude = kAltitude;
156 position.accuracy = kAccuracy;
157 position.timestamp =
158 base::Time::UnixEpoch() +
159 base::TimeDelta::FromMilliseconds(kGeolocationTime);
160 scoped_refptr<content::MessageLoopRunner> runner =
161 new content::MessageLoopRunner;
162 content::GeolocationProvider::OverrideLocationForTesting(
163 position, runner->QuitClosure());
164 runner->Run();
165
126 WebKit::WebScreenInfo screen_info; 166 WebKit::WebScreenInfo screen_info;
127 screen_info.depth = kScreenColorDepth; 167 screen_info.depth = kScreenColorDepth;
128 screen_info.rect = WebKit::WebRect(kScreenBounds); 168 screen_info.rect = WebKit::WebRect(kScreenBounds);
129 screen_info.availableRect = WebKit::WebRect(kAvailableScreenBounds); 169 screen_info.availableRect = WebKit::WebRect(kAvailableScreenBounds);
130 170
131 internal::GetFingerprintInternal( 171 internal::GetFingerprintInternal(
132 kGaiaId, kWindowBounds, kContentBounds, screen_info, "25.0.0.123", 172 kGaiaId, kWindowBounds, kContentBounds, screen_info, "25.0.0.123",
133 kCharset, kAcceptLanguages, base::Time::Now(), DIALOG_TYPE_AUTOCHECKOUT, 173 kCharset, kAcceptLanguages, base::Time::Now(), DIALOG_TYPE_AUTOCHECKOUT,
134 g_browser_process->GetApplicationLocale(), 174 g_browser_process->GetApplicationLocale(),
135 base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback, 175 base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback,
136 base::Unretained(this))); 176 base::Unretained(this)));
137 177
138 // Wait for the callback to be called. 178 // Wait for the callback to be called.
139 message_loop_.Run(); 179 message_loop_.Run();
140 } 180 }
141 181
142 } // namespace risk 182 } // namespace risk
143 } // namespace autofill 183 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/browser/risk/fingerprint.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698