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

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
« no previous file with comments | « chrome_frame/test/automation_client_mock.cc ('k') | chrome_frame/utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_frame/test/util_unittests.cc
===================================================================
--- chrome_frame/test/util_unittests.cc (revision 68895)
+++ 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/string_util.h"
+#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
+#include "chrome_frame/navigation_constraints.h"
#include "chrome_frame/test/chrome_frame_test_utils.h"
#include "chrome_frame/utils.h"
@@ -228,8 +231,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));
amit 2010/12/13 23:45:27 nit: spacing around &
ananta 2010/12/14 00:36:27 Done.
+ 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))
amit 2010/12/13 23:45:27 nit: fits on the line above
ananta 2010/12/14 00:36:27 Done.
+ return zone != URLZONE_UNTRUSTED;
+ return false;
+}
+
TEST_F(UtilTests, CanNavigateTest) {
- MockIInternetSecurityManager mock;
+ MockNavigationConstraintsZoneOverride mock;
struct Zones {
const wchar_t* url_prefix;
@@ -247,78 +279,120 @@
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;
}
+}
- bool enable_gcf = GetConfigBool(false, kAllowUnsafeURLs);
- SetConfigBool(kAllowUnsafeURLs, true);
+TEST_F(UtilTests, CanNavigateTestDenyAll) {
+ MockNavigationConstraints mock;
- 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);
- EXPECT_EQ(test.unsafe_expected, actual) << "Failure url: " << test.url;
+ 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[] = {
amit 2010/12/13 23:45:27 would it make sense to use the same 'test_cases' l
ananta 2010/12/14 00:36:27 Done.
+ {"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));
}
+}
- SetConfigBool(kAllowUnsafeURLs, enable_gcf);
+TEST_F(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_F(UtilTests, CanNavigateTestAllowAllUnsafeUrs) {
amit 2010/12/13 23:45:27 nit:CanNavigateTestAllowAllUnsafeUr'l's
ananta 2010/12/14 00:36:27 Done.
+ 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_F(UtilTests, IsDefaultRendererTest) {
RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS);
EXPECT_TRUE(config_key.Valid());
« no previous file with comments | « chrome_frame/test/automation_client_mock.cc ('k') | chrome_frame/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698