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

Side by Side Diff: chrome/browser/net/safe_search_util_unittest.cc

Issue 354183002: Enforce SafetyMode for YouTube if prefs::kForceSafeSearch is on. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert string_util.h change Created 6 years, 5 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 | « chrome/browser/net/safe_search_util.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014 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/net/safe_search_util.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/string_piece.h"
9 #include "net/http/http_request_headers.h"
10 #include "net/url_request/url_request_test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h"
13
14 class SafeSearchUtilTest : public ::testing::Test {
15 protected:
16 SafeSearchUtilTest() {}
17 virtual ~SafeSearchUtilTest() {}
18
19 scoped_ptr<net::URLRequest> CreateYoutubeRequest() {
20 return context_.CreateRequest(GURL("http://www.youtube.com"),
21 net::DEFAULT_PRIORITY,
22 NULL,
23 NULL);
24 }
25
26 scoped_ptr<net::URLRequest> CreateNonYoutubeRequest() {
27 return context_.CreateRequest(GURL("http://www.notyoutube.com"),
28 net::DEFAULT_PRIORITY,
29 NULL,
30 NULL);
31 }
32
33 static void SetCookie(net::HttpRequestHeaders* headers,
34 const std::string& value) {
35 headers->SetHeader(base::StringPiece(net::HttpRequestHeaders::kCookie),
36 base::StringPiece(value));
37 }
38
39 static void CheckHeaders(net::URLRequest* request,
40 const std::string& header_string_original,
41 const std::string& header_string_expected) {
42 net::HttpRequestHeaders headers;
43 SetCookie(&headers, header_string_original);
44 safe_search_util::ForceYouTubeSafetyMode(request, &headers);
45
46 net::HttpRequestHeaders headers_expected;
47 SetCookie(&headers_expected, header_string_expected);
48 EXPECT_EQ(headers_expected.ToString(), headers.ToString());
49 }
50
51 base::MessageLoop message_loop_;
52 net::TestURLRequestContext context_;
53 };
54
55 // ForceGoogleSafeSearch is already tested quite extensively in
56 // ChromeNetworkDelegateSafeSearchTest (in chrome_network_delegate_unittest.cc),
57 // so we won't test it again here.
58
59 TEST_F(SafeSearchUtilTest, CreateYoutubePrefCookie) {
60 scoped_ptr<net::URLRequest> request = CreateYoutubeRequest();
61 CheckHeaders(request.get(),
62 "OtherCookie=value",
63 "OtherCookie=value; PREF=f2=8000000");
64 }
65
66 TEST_F(SafeSearchUtilTest, ModifyYoutubePrefCookie) {
67 scoped_ptr<net::URLRequest> request = CreateYoutubeRequest();
68 CheckHeaders(request.get(),
69 "PREF=f1=123; OtherCookie=value",
70 "PREF=f1=123&f2=8000000; OtherCookie=value");
71 CheckHeaders(request.get(),
72 "PREF=",
73 "PREF=f2=8000000");
74 CheckHeaders(request.get(),
75 "PREF=\"\"",
76 "PREF=\"f2=8000000\"");
77 CheckHeaders(request.get(),
78 "PREF=f1=123&f2=4321&foo=bar",
79 "PREF=f1=123&f2=8004321&foo=bar");
80 CheckHeaders(request.get(),
81 "PREF=\"f1=1&f2=4321\"; OtherCookie=value",
82 "PREF=\"f1=1&f2=8004321\"; OtherCookie=value");
83 }
84
85 TEST_F(SafeSearchUtilTest, DoesntTouchNonYoutubeURL) {
86 scoped_ptr<net::URLRequest> request = CreateNonYoutubeRequest();
87 CheckHeaders(request.get(),
88 "PREF=f2=0",
89 "PREF=f2=0");
90 }
OLDNEW
« no previous file with comments | « chrome/browser/net/safe_search_util.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698