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

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: YouTube 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
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 void SetCookie(net::HttpRequestHeaders* headers, const std::string& value) {
34 headers->SetHeader(base::StringPiece(net::HttpRequestHeaders::kCookie),
35 base::StringPiece(value));
36 }
37
38 base::MessageLoop message_loop_;
39 net::TestURLRequestContext context_;
40 };
41
42 // ForceGoogleSafeSearch is already tested quite extensively in
43 // ChromeNetworkDelegateSafeSearchTest (in chrome_network_delegate_unittest.cc),
44 // so we won't test it again here.
45
46 TEST_F(SafeSearchUtilTest, CreateYoutubePrefCookie) {
47 scoped_ptr<net::URLRequest> request = CreateYoutubeRequest();
48 net::HttpRequestHeaders headers;
49 SetCookie(&headers, "OtherCookie=value");
50 safe_search_util::ForceYouTubeSafetyMode(request.get(), &headers);
51
52 net::HttpRequestHeaders headers_expected;
53 SetCookie(&headers_expected, "OtherCookie=value;PREF=f2=8000000");
54 EXPECT_EQ(headers_expected.ToString(), headers.ToString());
55 }
56
57 TEST_F(SafeSearchUtilTest, ModifyYoutubePrefCookie) {
58 scoped_ptr<net::URLRequest> request = CreateYoutubeRequest();
59 {
60 net::HttpRequestHeaders headers;
61 SetCookie(&headers, "PREF=f1=123;OtherCookie=value");
62 safe_search_util::ForceYouTubeSafetyMode(request.get(), &headers);
63
64 net::HttpRequestHeaders headers_expected;
65 SetCookie(&headers_expected, "PREF=f1=123&f2=8000000;OtherCookie=value");
66 EXPECT_EQ(headers_expected.ToString(), headers.ToString());
67 }
68 {
69 net::HttpRequestHeaders headers;
70 SetCookie(&headers, "PREF=f1=123&f2=4321&foo=bar");
battre 2014/07/08 13:43:06 did you check that uppler/lower cases of the hex n
Marc Treib 2014/07/08 14:16:15 YouTube uses lowercase as well (https://cs.corp.go
71 safe_search_util::ForceYouTubeSafetyMode(request.get(), &headers);
72
73 net::HttpRequestHeaders headers_expected;
74 SetCookie(&headers_expected, "PREF=f1=123&f2=8004321&foo=bar");
75 EXPECT_EQ(headers_expected.ToString(), headers.ToString());
76 }
77 }
78
79 TEST_F(SafeSearchUtilTest, DoesntTouchNonYoutubeURL) {
80 scoped_ptr<net::URLRequest> request = CreateNonYoutubeRequest();
81 net::HttpRequestHeaders headers;
82 SetCookie(&headers, "PREF=f2=0");
83 net::HttpRequestHeaders headers_expected;
84 headers_expected.CopyFrom(headers);
85 safe_search_util::ForceYouTubeSafetyMode(request.get(), &headers);
86
87 EXPECT_EQ(headers_expected.ToString(), headers.ToString());
88 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698