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

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

Issue 11612017: [Autofill] Add protobuf for Google Wallet risk parameters and a utility function for filling it out. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 12 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autofill/risk/fingerprint.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "base/prefs/public/pref_service_base.h"
10 #include "chrome/browser/autofill/risk/proto/fingerprint.pb.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/testing_pref_service.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gfx/rect.h"
16
17 namespace autofill {
18 namespace risk {
19
20 const int64 kGaiaId = 99194853094755497;
21 const char kCharset[] = "UTF-8";
22 const char kAcceptLanguages[] = "en-US,en";
23
24 class AutofillRiskFingerprintTest : public InProcessBrowserTest {
25 public:
26 AutofillRiskFingerprintTest()
27 : kWindowBounds(2, 3, 5, 7),
28 kContentBounds(11, 13, 17, 37),
29 message_loop_(MessageLoop::TYPE_UI) {}
30
31 void GetFingerprintTestCallback(scoped_ptr<Fingerprint> fingerprint) {
32 // Verify that all fields Chrome can fill have been filled.
33 ASSERT_TRUE(fingerprint->has_machine_characteristics());
34 const Fingerprint_MachineCharacteristics& machine =
35 fingerprint->machine_characteristics();
36 ASSERT_TRUE(machine.has_operating_system_build());
37 ASSERT_TRUE(machine.has_browser_install_time_ms());
38 ASSERT_GT(machine.font_size(), 0);
39 ASSERT_GT(machine.plugin_size(), 0);
40 ASSERT_TRUE(machine.has_utc_offset_ms());
41 ASSERT_TRUE(machine.has_browser_language());
42 ASSERT_GT(machine.requested_language_size(), 0);
43 ASSERT_TRUE(machine.has_charset());
44 ASSERT_TRUE(machine.has_screen_count());
45 ASSERT_TRUE(machine.has_screen_size());
46 ASSERT_TRUE(machine.screen_size().has_width());
47 ASSERT_TRUE(machine.screen_size().has_height());
48 ASSERT_TRUE(machine.has_user_agent());
49 ASSERT_TRUE(machine.has_cpu());
50 ASSERT_TRUE(machine.cpu().has_vendor_name());
51 ASSERT_TRUE(machine.cpu().has_brand());
52 ASSERT_TRUE(machine.has_ram());
53 ASSERT_TRUE(machine.has_graphics_card());
54 ASSERT_TRUE(machine.graphics_card().has_vendor_id());
55 ASSERT_TRUE(machine.graphics_card().has_device_id());
56 ASSERT_TRUE(machine.has_browser_build());
57
58 ASSERT_TRUE(fingerprint->has_transient_state());
59 const Fingerprint_TransientState& transient_state =
60 fingerprint->transient_state();
61 ASSERT_TRUE(transient_state.has_inner_window_size());
62 ASSERT_TRUE(transient_state.has_outer_window_size());
63 ASSERT_TRUE(transient_state.inner_window_size().has_width());
64 ASSERT_TRUE(transient_state.inner_window_size().has_height());
65 ASSERT_TRUE(transient_state.outer_window_size().has_width());
66 ASSERT_TRUE(transient_state.outer_window_size().has_height());
67
68 ASSERT_TRUE(fingerprint->has_metadata());
69 ASSERT_TRUE(fingerprint->metadata().has_timestamp_ms());
70 ASSERT_TRUE(fingerprint->metadata().has_gaia_id());
71 ASSERT_TRUE(fingerprint->metadata().has_fingerprinter_version());
72
73 // Some values have exact known (mocked out) values:
74 ASSERT_EQ(2, machine.requested_language_size());
75 EXPECT_EQ("en-US", machine.requested_language(0));
76 EXPECT_EQ("en", machine.requested_language(1));
77 EXPECT_EQ(kCharset, machine.charset());
78 EXPECT_EQ(kContentBounds.width(),
79 transient_state.inner_window_size().width());
80 EXPECT_EQ(kContentBounds.height(),
81 transient_state.inner_window_size().height());
82 EXPECT_EQ(kWindowBounds.width(),
83 transient_state.outer_window_size().width());
84 EXPECT_EQ(kWindowBounds.height(),
85 transient_state.outer_window_size().height());
86 EXPECT_EQ(kGaiaId, fingerprint->metadata().gaia_id());
87
88 message_loop_.Quit();
89 }
90
91 protected:
92 const gfx::Rect kWindowBounds;
93 const gfx::Rect kContentBounds;
94 MessageLoop message_loop_;
95 };
96
97 // Test that getting a fingerprint works on some basic level.
98 IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, GetFingerprint) {
99 TestingPrefService prefs;
100 prefs.RegisterStringPref(prefs::kDefaultCharset, kCharset,
101 PrefServiceBase::UNSYNCABLE_PREF);
102 prefs.RegisterStringPref(prefs::kAcceptLanguages, kAcceptLanguages,
103 PrefServiceBase::UNSYNCABLE_PREF);
104
105 GetFingerprint(
106 kGaiaId, kWindowBounds, kContentBounds, prefs,
107 base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback,
108 base::Unretained(this)));
109
110 // Wait for the callback to be called.
111 message_loop_.Run();
112 }
113
114 } // namespace risk
115 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698