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

Unified Diff: chrome_frame/test/util_unittests.cc

Issue 5698005: Add support for gcf:about:plugins in chrome frame full tab mode. The URL vali... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome_frame/test/util_unittests.cc
===================================================================
--- chrome_frame/test/util_unittests.cc (revision 68604)
+++ chrome_frame/test/util_unittests.cc (working copy)
@@ -5,7 +5,10 @@
#include "base/file_path.h"
#include "base/file_version_info.h"
#include "base/file_version_info_win.h"
+#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
+
+#include "chrome_frame/chrome_frame_delegate.h"
#include "chrome_frame/utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -202,8 +205,37 @@
HRESULT(DWORD zone, IEnumString** enum_string, DWORD flags));
};
+// This class provides a partial mock for the NavigationConstraints
+// interface by providing specialized zone overrides.
+class MockNavigationConstraintsZoneOverride
+ : public NavigationConstraintsImpl {
+ public:
+ MOCK_METHOD1(IsZoneAllowed, bool(const GURL&url));
+};
+
+// Mock NavigationConstraints
+class MockNavigationConstraints : public NavigationConstraints {
+ public:
+ MOCK_METHOD0(AllowUnsafeUrls, bool());
+ MOCK_METHOD1(IsSchemeAllowed, bool(const GURL&url));
+ MOCK_METHOD1(IsZoneAllowed, bool(const GURL&url));
+};
+
+// Matcher which returns true if the URL passed in starts with the prefix
+// specified.
+MATCHER_P(UrlPathStartsWith, url_prefix, "url starts with prefix") {
+ return StartsWith(UTF8ToWide(arg.spec()), url_prefix, false);
+}
+
+ACTION_P3(HandleZone, mock, url_prefix, zone) {
+ if (StartsWith(UTF8ToWide(arg0.spec()),
+ url_prefix, false))
+ return zone != URLZONE_UNTRUSTED;
+ return false;
+}
+
TEST(UtilTests, CanNavigateTest) {
- MockIInternetSecurityManager mock;
+ MockNavigationConstraintsZoneOverride mock;
struct Zones {
const wchar_t* url_prefix;
@@ -221,63 +253,40 @@
for (int i = 0; i < arraysize(test_zones); ++i) {
const Zones& zone = test_zones[i];
- EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(zone.url_prefix),
- testing::_, testing::_))
- .WillRepeatedly(testing::DoAll(
- testing::SetArgumentPointee<1>(zone.zone),
- testing::Return(S_OK)));
+ EXPECT_CALL(mock, IsZoneAllowed(UrlPathStartsWith(zone.url_prefix)))
+ .WillRepeatedly(testing::Return(zone.zone != URLZONE_UNTRUSTED));
}
struct Cases {
const char* url;
- bool is_privileged;
bool default_expected;
bool unsafe_expected;
} test_cases[] = {
// Invalid URL
- { " ", false, false, false },
- { "foo bar", true, false, false },
+ { " ", false, false },
+ { "foo bar", false, false },
// non-privileged test cases
- { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false,
- true, true },
- { "http://untrusted/bar.html", false, false, true },
- { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false,
- true, true },
- { "view-source:http://www.google.ca", false, true, true },
- { "view-source:javascript:alert('foo');", false, false, true },
- { "about:blank", false, true, true },
- { "About:Version", false, true, true },
- { "about:config", false, false, true },
- { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, false,
- true },
- { "ftp://www.google.ca", false, false, true },
- { "file://www.google.ca", false, false, true },
- { "file://C:\boot.ini", false, false, true },
- { "SIP:someone@10.1.2.3", false, false, true },
-
- // privileged test cases
- { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, true,
- true },
- { "http://untrusted/bar.html", true, false, true },
- { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, true,
- true },
- { "view-source:http://www.google.ca", true, true, true },
- { "view-source:javascript:alert('foo');", true, false, true },
- { "about:blank", true, true, true },
- { "About:Version", true, true, true },
- { "about:config", true, false, true },
- { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", true, true,
- true },
- { "ftp://www.google.ca", true, false, true },
- { "file://www.google.ca", true, false, true },
- { "file://C:\boot.ini", true, false, true },
- { "sip:someone@10.1.2.3", false, false, true },
+ { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true,
+ true },
+ { "http://untrusted/bar.html", false, true },
+ { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true,
+ true },
+ { "view-source:http://www.google.ca", true, true },
+ { "view-source:javascript:alert('foo');", false, true },
+ { "about:blank", true, true },
+ { "About:Version", true, true },
+ { "about:config", false, true },
+ { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, true },
+ { "ftp://www.google.ca", false, true },
+ { "file://www.google.ca", false, true },
+ { "file://C:\boot.ini", false, true },
+ { "SIP:someone@10.1.2.3", false, true },
};
for (int i = 0; i < arraysize(test_cases); ++i) {
const Cases& test = test_cases[i];
- bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged);
+ bool actual = CanNavigate(GURL(test.url), &mock);
EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url;
}
@@ -286,13 +295,89 @@
for (int i = 0; i < arraysize(test_cases); ++i) {
const Cases& test = test_cases[i];
- bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged);
+ bool actual = CanNavigate(GURL(test.url), &mock);
EXPECT_EQ(test.unsafe_expected, actual) << "Failure url: " << test.url;
}
SetConfigBool(kAllowUnsafeURLs, enable_gcf);
}
+TEST(UtilTests, CanNavigateTestDenyAll) {
amit 2010/12/10 23:56:17 nice new tests
+ MockNavigationConstraints mock;
+
+ EXPECT_CALL(mock, IsZoneAllowed(testing::_))
+ .Times(testing::AnyNumber())
+ .WillRepeatedly(testing::Return(false));
+
+ EXPECT_CALL(mock, IsSchemeAllowed(testing::_))
+ .Times(testing::AnyNumber())
+ .WillRepeatedly(testing::Return(false));
+
+ EXPECT_CALL(mock, AllowUnsafeUrls())
+ .Times(testing::AnyNumber())
+ .WillRepeatedly(testing::Return(false));
+
+ char *urls[] = {
+ {"http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
+ {"http://untrusted/bar.html"},
+ {"http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
+ {"view-source:http://www.google.ca"},
+ {"view-source:javascript:alert('foo');"},
+ {"about:blank"},
+ {"About:Version"},
+ };
+
+ for (int i = 0; i < arraysize(urls); ++i) {
+ EXPECT_FALSE(CanNavigate(GURL(urls[i]), &mock));
+ }
+}
+
+TEST(UtilTests, CanNavigateTestAllowAll) {
+ MockNavigationConstraints mock;
+
+ EXPECT_CALL(mock, AllowUnsafeUrls())
+ .Times(testing::AnyNumber())
+ .WillRepeatedly(testing::Return(false));
+
+ EXPECT_CALL(mock, IsSchemeAllowed(testing::_))
+ .Times(testing::AnyNumber())
+ .WillRepeatedly(testing::Return(true));
+
+ EXPECT_CALL(mock, IsZoneAllowed(testing::_))
+ .Times(testing::AnyNumber())
+ .WillRepeatedly(testing::Return(true));
+
+ char *urls[] = {
+ {"gcf:about:cache"},
+ {"gcf:http://www.google.com"},
+ {"view-source:javascript:alert('foo');"},
+ {"http://www.google.com"},
+ };
+
+ for (int i = 0; i < arraysize(urls); ++i) {
+ EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock));
+ }
+}
+
+TEST(UtilTests, CanNavigateTestAllowAllUnsafeUrs) {
+ MockNavigationConstraints mock;
+
+ EXPECT_CALL(mock, AllowUnsafeUrls())
+ .Times(testing::AnyNumber())
+ .WillRepeatedly(testing::Return(true));
+
+ char *urls[] = {
+ {"gcf:about:cache"},
+ {"gcf:http://www.google.com"},
+ {"view-source:javascript:alert('foo');"},
+ {"http://www.google.com"},
+ };
+
+ for (int i = 0; i < arraysize(urls); ++i) {
+ EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock));
+ }
+}
+
TEST(UtilTests, IsDefaultRendererTest) {
RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS);
EXPECT_TRUE(config_key.Valid());

Powered by Google App Engine
This is Rietveld 408576698