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

Side by Side Diff: third_party/WebKit/Source/core/loader/MixedContentCheckerTest.cpp

Issue 1415923015: Downgrade lock icon for broken-HTTPS subresources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add MixedContentChecker unit test Created 5 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "config.h" 5 #include "config.h"
6 #include "core/loader/MixedContentChecker.h" 6 #include "core/loader/MixedContentChecker.h"
7 7
8 #include "core/loader/EmptyClients.h"
8 #include "core/testing/DummyPageHolder.h" 9 #include "core/testing/DummyPageHolder.h"
9 #include "platform/weborigin/KURL.h" 10 #include "platform/weborigin/KURL.h"
10 #include "platform/weborigin/SecurityOrigin.h" 11 #include "platform/weborigin/SecurityOrigin.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "wtf/RefPtr.h" 13 #include "wtf/RefPtr.h"
13 #include <base/macros.h> 14 #include <base/macros.h>
14 15
15 namespace blink { 16 namespace blink {
16 17
17 TEST(MixedContentCheckerTest, IsMixedContent) 18 TEST(MixedContentCheckerTest, IsMixedContent)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); 61 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
61 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextScript) ; 62 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextScript) ;
62 EXPECT_EQ(MixedContentChecker::ContextTypeBlockable, MixedContentChecker::co ntextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent)); 63 EXPECT_EQ(MixedContentChecker::ContextTypeBlockable, MixedContentChecker::co ntextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent));
63 64
64 ResourceRequest optionallyBlockableMixedContent("http://example.test/foo.jpg "); 65 ResourceRequest optionallyBlockableMixedContent("http://example.test/foo.jpg ");
65 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); 66 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
66 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextImage); 67 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextImage);
67 EXPECT_EQ(MixedContentChecker::ContextTypeOptionallyBlockable, MixedContentC hecker::contextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent )); 68 EXPECT_EQ(MixedContentChecker::ContextTypeOptionallyBlockable, MixedContentC hecker::contextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent ));
68 } 69 }
69 70
71 namespace {
72
73 enum CertErrorsContentType {
Mike West 2015/11/27 05:30:38 Nit: No indentation.
estark 2015/11/28 02:46:56 Hmm, `git cl format` seems to like it this way.
74 DisplayedContentWithCertErrors,
75 RanContentWithCertErrors
76 };
77
78 struct ContentWithCertErrorsInfo {
79 KURL url;
80 KURL mainResourceUrl;
81 CertErrorsContentType contentType;
82 };
83
84 class CertErrorsTracker {
85 public:
86 CertErrorsTracker() {}
87 ~CertErrorsTracker() {}
88
89 const ContentWithCertErrorsInfo& contentWithCertErrorsInfo() { return m_ contentWithCertErrors; }
90
91 void didDisplayContentWithCertificateErrors(const KURL& url, const WebUR L& mainResourceUrl)
92 {
93 m_contentWithCertErrors.url = url;
94 m_contentWithCertErrors.mainResourceUrl = mainResourceUrl;
95 m_contentWithCertErrors.contentType = DisplayedContentWithCertErrors ;
96 }
97
98 void didRunContentWithCertificateErrors(const KURL& url, const WebURL& m ainResourceUrl)
99 {
100 m_contentWithCertErrors.url = url;
101 m_contentWithCertErrors.mainResourceUrl = mainResourceUrl;
102 m_contentWithCertErrors.contentType = RanContentWithCertErrors;
103 }
104
105 private:
106 ContentWithCertErrorsInfo m_contentWithCertErrors;
107 };
108
109 class TestCertErrorsFrameLoaderClient : public EmptyFrameLoaderClient {
110 public:
111 ~TestCertErrorsFrameLoaderClient() {}
112
113 static PassOwnPtrWillBeRawPtr<TestCertErrorsFrameLoaderClient> create(Ce rtErrorsTracker* tracker) { return adoptPtrWillBeNoop(new TestCertErrorsFrameLoa derClient(tracker)); }
114
115 void didDisplayContentWithCertificateErrors(const KURL& url, const CStri ng& securityInfo, const WebURL& mainResourceUrl, const CString& mainResourceSecu rityInfo)
116 {
117 m_tracker->didDisplayContentWithCertificateErrors(url, mainResourceU rl);
118 }
119
120 void didRunContentWithCertificateErrors(const KURL& url, const CString& securityInfo, const WebURL& mainResourceUrl, const CString& mainResourceSecurity Info)
121 {
122 m_tracker->didRunContentWithCertificateErrors(url, mainResourceUrl);
123 }
124
125 private:
126 TestCertErrorsFrameLoaderClient(CertErrorsTracker* tracker)
127 : m_tracker(tracker)
128 {
129 }
130 CertErrorsTracker* m_tracker;
131 };
Mike West 2015/11/27 05:30:38 This is fine, but I suspect you could do it more s
estark 2015/11/28 02:46:56 Ah, that is much better, thanks!
132
133 } // namespace
134
135 TEST(MixedContentCheckerTest, HandleCertificateError)
136 {
137 CertErrorsTracker certErrorsTracker;
138 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(1, 1), nullptr, TestCertErrorsFrameLoaderClient::create(&certErrorsTracker));
139
140 KURL mainResourceUrl(KURL(), "https://example.test");
141 KURL displayedUrl(KURL(), "https://example-displayed.test");
142 KURL ranUrl(KURL(), "https://example-ran.test");
143
144 dummyPageHolder->frame().document()->setURL(mainResourceUrl);
145 EXPECT_EQ(KURL(), certErrorsTracker.contentWithCertErrorsInfo().url);
146 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), ranUr l, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeNone, "");
147 EXPECT_EQ(ranUrl, certErrorsTracker.contentWithCertErrorsInfo().url);
148 EXPECT_EQ(mainResourceUrl, certErrorsTracker.contentWithCertErrorsInfo().mai nResourceUrl);
149
150 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), displ ayedUrl, WebURLRequest::RequestContextImage, WebURLRequest::FrameTypeNone, "");
Mike West 2015/11/27 05:30:38 In a magical future world where we've blocked all
estark 2015/11/28 02:46:56 Done.
151 EXPECT_EQ(displayedUrl, certErrorsTracker.contentWithCertErrorsInfo().url);
152 EXPECT_EQ(mainResourceUrl, certErrorsTracker.contentWithCertErrorsInfo().mai nResourceUrl);
153 }
154
70 } // namespace blink 155 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698