Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 namespace { | |
| 21 | |
| 22 const int64 kGaiaId = 99194853094755497; | |
| 23 const char kCharset[] = "UTF-8"; | |
| 24 const char kAcceptLanguages[] = "en-US,en"; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 class AutofillRiskFingerprintTest : public InProcessBrowserTest { | |
| 29 public: | |
| 30 AutofillRiskFingerprintTest() | |
| 31 : kWindowBounds(2, 3, 5, 7), | |
| 32 kContentBounds(11, 13, 17, 37), | |
| 33 message_loop_(MessageLoop::TYPE_UI) {} | |
| 34 | |
| 35 void GetFingerprintTestCallback(scoped_ptr<Fingerprint> fingerprint) { | |
| 36 // Verify that all fields Chrome can fill have been filled. | |
| 37 ASSERT_TRUE(fingerprint->has_machine_characteristics()); | |
| 38 const Fingerprint_MachineCharacteristics& machine = | |
| 39 fingerprint->machine_characteristics(); | |
| 40 ASSERT_TRUE(machine.has_operating_system_build()); | |
| 41 ASSERT_TRUE(machine.has_browser_install_time_ms()); | |
| 42 ASSERT_GT(machine.font_size(), 0); | |
| 43 ASSERT_GT(machine.plugin_size(), 0); | |
| 44 ASSERT_TRUE(machine.has_utc_offset_ms()); | |
| 45 ASSERT_TRUE(machine.has_browser_language()); | |
| 46 ASSERT_GT(machine.requested_language_size(), 0); | |
| 47 ASSERT_TRUE(machine.has_charset()); | |
| 48 ASSERT_TRUE(machine.has_screen_count()); | |
|
Evan Stade
2012/12/21 22:37:08
does this mean the test will fail on a headless ma
Ilya Sherman
2012/12/22 01:22:00
The test would still pass on a headless machine.
| |
| 49 ASSERT_TRUE(machine.has_screen_size()); | |
| 50 ASSERT_TRUE(machine.screen_size().has_width()); | |
| 51 ASSERT_TRUE(machine.screen_size().has_height()); | |
| 52 ASSERT_TRUE(machine.has_user_agent()); | |
| 53 ASSERT_TRUE(machine.has_cpu()); | |
|
Evan Stade
2012/12/21 22:37:08
do all of these need to be ASSERT instead of EXPEC
Ilya Sherman
2012/12/22 01:22:00
Some of them need to be ASSERTs for the sake of su
Evan Stade
2012/12/22 02:17:34
EXPECT cuts down on the number of fix-compile-run
Ilya Sherman
2012/12/26 23:10:28
Fair enough, though for this particular test's ASS
| |
| 54 ASSERT_TRUE(machine.cpu().has_vendor_name()); | |
| 55 ASSERT_TRUE(machine.cpu().has_brand()); | |
| 56 ASSERT_TRUE(machine.has_ram()); | |
| 57 ASSERT_TRUE(machine.has_graphics_card()); | |
| 58 ASSERT_TRUE(machine.graphics_card().has_vendor_id()); | |
| 59 ASSERT_TRUE(machine.graphics_card().has_device_id()); | |
| 60 ASSERT_TRUE(machine.has_browser_build()); | |
| 61 | |
| 62 ASSERT_TRUE(fingerprint->has_transient_state()); | |
| 63 const Fingerprint_TransientState& transient_state = | |
| 64 fingerprint->transient_state(); | |
| 65 ASSERT_TRUE(transient_state.has_inner_window_size()); | |
| 66 ASSERT_TRUE(transient_state.has_outer_window_size()); | |
| 67 ASSERT_TRUE(transient_state.inner_window_size().has_width()); | |
| 68 ASSERT_TRUE(transient_state.inner_window_size().has_height()); | |
| 69 ASSERT_TRUE(transient_state.outer_window_size().has_width()); | |
| 70 ASSERT_TRUE(transient_state.outer_window_size().has_height()); | |
| 71 | |
| 72 ASSERT_TRUE(fingerprint->has_metadata()); | |
| 73 ASSERT_TRUE(fingerprint->metadata().has_timestamp_ms()); | |
| 74 ASSERT_TRUE(fingerprint->metadata().has_gaia_id()); | |
| 75 ASSERT_TRUE(fingerprint->metadata().has_fingerprinter_version()); | |
| 76 | |
| 77 // Some values have exact known (mocked out) values: | |
| 78 ASSERT_EQ(2, machine.requested_language_size()); | |
| 79 EXPECT_EQ("en-US", machine.requested_language(0)); | |
| 80 EXPECT_EQ("en", machine.requested_language(1)); | |
| 81 EXPECT_EQ(kCharset, machine.charset()); | |
| 82 EXPECT_EQ(kContentBounds.width(), | |
| 83 transient_state.inner_window_size().width()); | |
| 84 EXPECT_EQ(kContentBounds.height(), | |
| 85 transient_state.inner_window_size().height()); | |
| 86 EXPECT_EQ(kWindowBounds.width(), | |
| 87 transient_state.outer_window_size().width()); | |
| 88 EXPECT_EQ(kWindowBounds.height(), | |
| 89 transient_state.outer_window_size().height()); | |
| 90 EXPECT_EQ(kGaiaId, fingerprint->metadata().gaia_id()); | |
| 91 | |
| 92 message_loop_.Quit(); | |
| 93 } | |
| 94 | |
| 95 protected: | |
| 96 const gfx::Rect kWindowBounds; | |
| 97 const gfx::Rect kContentBounds; | |
| 98 MessageLoop message_loop_; | |
| 99 }; | |
| 100 | |
| 101 // Test that getting a fingerprint works on some basic level. | |
| 102 IN_PROC_BROWSER_TEST_F(AutofillRiskFingerprintTest, GetFingerprint) { | |
| 103 TestingPrefService prefs; | |
| 104 prefs.RegisterStringPref(prefs::kDefaultCharset, kCharset, | |
| 105 PrefServiceBase::UNSYNCABLE_PREF); | |
| 106 prefs.RegisterStringPref(prefs::kAcceptLanguages, kAcceptLanguages, | |
| 107 PrefServiceBase::UNSYNCABLE_PREF); | |
| 108 | |
| 109 GetFingerprint( | |
| 110 kGaiaId, kWindowBounds, kContentBounds, prefs, | |
| 111 base::Bind(&AutofillRiskFingerprintTest::GetFingerprintTestCallback, | |
| 112 base::Unretained(this))); | |
| 113 | |
| 114 // Wait for the callback to be called. | |
| 115 message_loop_.Run(); | |
| 116 } | |
| 117 | |
| 118 } // namespace risk | |
| 119 } // namespace autofill | |
| OLD | NEW |