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

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: Fix test compile Created 7 years, 10 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_GT(machine.font_size(), 0);
38 ASSERT_GT(machine.plugin_size(), 0);
39 ASSERT_TRUE(machine.has_utc_offset_ms());
40 ASSERT_TRUE(machine.has_browser_language());
41 ASSERT_GT(machine.requested_language_size(), 0);
42 ASSERT_TRUE(machine.has_charset());
43 ASSERT_TRUE(machine.has_screen_count());
44 ASSERT_TRUE(machine.has_screen_size());
45 ASSERT_TRUE(machine.screen_size().has_width());
46 ASSERT_TRUE(machine.screen_size().has_height());
47 ASSERT_TRUE(machine.has_user_agent());
48 ASSERT_TRUE(machine.has_cpu());
49 ASSERT_TRUE(machine.cpu().has_vendor_name());
50 ASSERT_TRUE(machine.cpu().has_brand());
51 ASSERT_TRUE(machine.has_ram());
52 ASSERT_TRUE(machine.has_graphics_card());
53 ASSERT_TRUE(machine.graphics_card().has_vendor_id());
54 ASSERT_TRUE(machine.graphics_card().has_device_id());
55 ASSERT_TRUE(machine.has_browser_build());
56
57 ASSERT_TRUE(fingerprint->has_transient_state());
58 const Fingerprint_TransientState& transient_state =
59 fingerprint->transient_state();
60 ASSERT_TRUE(transient_state.has_inner_window_size());
61 ASSERT_TRUE(transient_state.has_outer_window_size());
62 ASSERT_TRUE(transient_state.inner_window_size().has_width());
63 ASSERT_TRUE(transient_state.inner_window_size().has_height());
64 ASSERT_TRUE(transient_state.outer_window_size().has_width());
65 ASSERT_TRUE(transient_state.outer_window_size().has_height());
66
67 ASSERT_TRUE(fingerprint->has_metadata());
68 ASSERT_TRUE(fingerprint->metadata().has_timestamp_ms());
69 ASSERT_TRUE(fingerprint->metadata().has_gaia_id());
70 ASSERT_TRUE(fingerprint->metadata().has_fingerprinter_version());
71
72 // Some values have exact known (mocked out) values:
73 ASSERT_EQ(2, machine.requested_language_size());
74 EXPECT_EQ("en-US", machine.requested_language(0));
75 EXPECT_EQ("en", machine.requested_language(1));
76 EXPECT_EQ(kCharset, machine.charset());
77 EXPECT_EQ(kContentBounds.width(),
78 transient_state.inner_window_size().width());
79 EXPECT_EQ(kContentBounds.height(),
80 transient_state.inner_window_size().height());
81 EXPECT_EQ(kWindowBounds.width(),
82 transient_state.outer_window_size().width());
83 EXPECT_EQ(kWindowBounds.height(),
84 transient_state.outer_window_size().height());
85 EXPECT_EQ(kGaiaId, fingerprint->metadata().gaia_id());
86
87 message_loop_.Quit();
88 }
89
90 protected:
91 const gfx::Rect kWindowBounds;
92 const gfx::Rect kContentBounds;
93 MessageLoop message_loop_;
94 };
95
96 // Test that getting a fingerprint works on some basic level.
97 IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, GetFingerprint) {
98 TestingPrefServiceSimple prefs;
99 prefs.RegisterStringPref(prefs::kDefaultCharset, kCharset);
100 prefs.RegisterStringPref(prefs::kAcceptLanguages, kAcceptLanguages);
101
102 GetFingerprint(
103 kGaiaId, kWindowBounds, kContentBounds, prefs,
104 base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback,
105 base::Unretained(this)));
106
107 // Wait for the callback to be called.
108 message_loop_.Run();
109 }
110
111 } // namespace risk
112 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/risk/fingerprint.cc ('k') | chrome/browser/autofill/risk/proto/fingerprint.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698