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

Side by Side Diff: chrome/browser/do_not_track_browsertest.cc

Issue 10960042: Add navigator.doNotTrack property (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | chrome/browser/renderer_preferences_util.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 "base/string16.h" 5 #include "base/string16.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/prefs/pref_service.h" 7 #include "chrome/browser/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_tabstrip.h" 10 #include "chrome/browser/ui/browser_tabstrip.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/in_process_browser_test.h" 12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/test/browser_test_utils.h"
14 16
15 typedef InProcessBrowserTest DoNotTrackTest; 17 typedef InProcessBrowserTest DoNotTrackTest;
16 18
17 // Check that the DNT header is sent when the corresponding preference is set. 19 // Check that the DNT header is sent when the corresponding preference is set.
18 IN_PROC_BROWSER_TEST_F(DoNotTrackTest, Simple) { 20 IN_PROC_BROWSER_TEST_F(DoNotTrackTest, Simple) {
19 ASSERT_TRUE(test_server()->Start()); 21 ASSERT_TRUE(test_server()->Start());
20 22
21 PrefService* prefs = browser()->profile()->GetPrefs(); 23 PrefService* prefs = browser()->profile()->GetPrefs();
22 prefs->SetBoolean(prefs::kEnableDoNotTrack, true); 24 prefs->SetBoolean(prefs::kEnableDoNotTrack, true);
23 25
(...skipping 22 matching lines...) Expand all
46 ui_test_utils::NavigateToURL(browser(), url); 48 ui_test_utils::NavigateToURL(browser(), url);
47 49
48 int matches = ui_test_utils::FindInPage( 50 int matches = ui_test_utils::FindInPage(
49 chrome::GetActiveTabContents(browser()), 51 chrome::GetActiveTabContents(browser()),
50 string16(ASCIIToUTF16("1")), 52 string16(ASCIIToUTF16("1")),
51 true /* forward */, false /* match case */, NULL /* ordinal */, 53 true /* forward */, false /* match case */, NULL /* ordinal */,
52 NULL /* selection_rect */); 54 NULL /* selection_rect */);
53 55
54 EXPECT_EQ(1, matches); 56 EXPECT_EQ(1, matches);
55 } 57 }
58
59 // Check that the DOM property is set when the corresponding preference is set.
60 IN_PROC_BROWSER_TEST_F(DoNotTrackTest, DOMProperty) {
61 PrefService* prefs = browser()->profile()->GetPrefs();
62 prefs->SetBoolean(prefs::kEnableDoNotTrack, true);
63
64 ASSERT_NO_FATAL_FAILURE(content::WaitForLoadStop(
65 chrome::GetActiveWebContents(browser())));
66
67 std::string do_not_track;
68 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString(
69 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
70 std::wstring(),
71 L"window.domAutomationController.send(navigator.doNotTrack)",
72 &do_not_track));
73 EXPECT_EQ("1", do_not_track);
74
75 // Reset flag and check that the changed value is propagated to the existing
76 // renderer.
77 prefs->SetBoolean(prefs::kEnableDoNotTrack, false);
78
79 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractString(
80 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
81 std::wstring(),
82 L"window.domAutomationController.send("
83 L"navigator.doNotTrack === null ? '0' : '1')",
84 &do_not_track));
85 EXPECT_EQ("0", do_not_track);
86 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_preferences_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698