summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 22:52:34 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-30 22:52:34 +0000
commit57319e14f7429ef47086acfa1acf1e7f75c956a7 (patch)
tree7c20eef391e725a52d47a17fb7446a2163afe330 /chrome_frame/test
parentc1a9b640c320f20f6b797e103416195a14b2401d (diff)
downloadchromium_src-57319e14f7429ef47086acfa1acf1e7f75c956a7.zip
chromium_src-57319e14f7429ef47086acfa1acf1e7f75c956a7.tar.gz
chromium_src-57319e14f7429ef47086acfa1acf1e7f75c956a7.tar.bz2
Add a setting to CF to remove 'chromeframe' from the UserAgent on a per-pattern basis.
Useful for testing and dealing with sites with broken UA parsing. BUG=117157 TEST=chrome_frame_tests,chrome_frame_unittests,add a ExcludeUAFromDomain key to the CF settings, add some pattern values, observe that the UA string does not contain CF. Review URL: http://codereview.chromium.org/9720001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129985 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test')
-rw-r--r--chrome_frame/test/html_util_unittests.cc151
-rw-r--r--chrome_frame/test/http_negotiate_unittest.cc92
-rw-r--r--chrome_frame/test/util_unittests.cc13
3 files changed, 178 insertions, 78 deletions
diff --git a/chrome_frame/test/html_util_unittests.cc b/chrome_frame/test/html_util_unittests.cc
index 95a408f..827dfc7 100644
--- a/chrome_frame/test/html_util_unittests.cc
+++ b/chrome_frame/test/html_util_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -319,79 +319,96 @@ TEST_F(HtmlUtilUnittest, IEConditionalCommentNonTerminatedTest) {
ASSERT_EQ(2, boo_tag_list.size());
}
-TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) {
- struct TestCase {
- std::string input_;
- std::string expected_;
- } test_cases[] = {
- {
- "", ""
- }, {
- "Mozilla/4.7 [en] (WinNT; U)",
- "Mozilla/4.7 [en] (WinNT; U; chromeframe/0.0.0.0)"
- }, {
- "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)",
- "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT; chromeframe/0.0.0.0)"
- }, {
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; "
- ".NET CLR 1.1.4322)",
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; "
- ".NET CLR 1.1.4322; chromeframe/0.0.0.0)"
- }, {
- "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 5.11 [en]",
- "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0; chromeframe/0.0.0.0) "
- "Opera 5.11 [en]"
- }, {
- "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
- "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; "
- "chromeframe/0.0.0.0)"
- }, {
- "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) "
- "Gecko/20030208 Netscape/7.02",
- "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2; "
- "chromeframe/0.0.0.0) Gecko/20030208 Netscape/7.02"
- }, {
- "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040612 "
- "Firefox/0.8",
- "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6; chromeframe/0.0.0.0) "
- "Gecko/20040612 Firefox/0.8"
- }, {
- "Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)",
- "Mozilla/5.0 (compatible; Konqueror/3.2; Linux; chromeframe/0.0.0.0) "
- "(KHTML, like Gecko)"
- }, {
- "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6h",
- "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 "
- "OpenSSL/0.9.6h chromeframe/0.0.0.0",
- }, {
- "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.7.10) "
- "Gecko/20050716 Firefox/1.0.6",
- "Mozilla/5.0 (X11; U; Linux i686 (x86_64; chromeframe/0.0.0.0); en-US; "
- "rv:1.7.10) Gecko/20050716 Firefox/1.0.6"
- }, {
- "Invalid/1.1 ((((((",
- "Invalid/1.1 (((((( chromeframe/0.0.0.0",
- }, {
- "Invalid/1.1 ()))))",
- "Invalid/1.1 ( chromeframe/0.0.0.0)))))",
- }, {
- "Strange/1.1 ()",
- "Strange/1.1 ( chromeframe/0.0.0.0)",
- }
- };
+struct UserAgentTestCase {
+ std::string input_;
+ std::string expected_;
+} user_agent_test_cases[] = {
+ {
+ "", ""
+ }, {
+ "Mozilla/4.7 [en] (WinNT; U)",
+ "Mozilla/4.7 [en] (WinNT; U; chromeframe/0.0.0.0)"
+ }, {
+ "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)",
+ "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT; chromeframe/0.0.0.0)"
+ }, {
+ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; "
+ ".NET CLR 1.1.4322)",
+ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; "
+ ".NET CLR 1.1.4322; chromeframe/0.0.0.0)"
+ }, {
+ "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 5.11 [en]",
+ "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0; chromeframe/0.0.0.0) "
+ "Opera 5.11 [en]"
+ }, {
+ "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
+ "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; "
+ "chromeframe/0.0.0.0)"
+ }, {
+ "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) "
+ "Gecko/20030208 Netscape/7.02",
+ "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2; "
+ "chromeframe/0.0.0.0) Gecko/20030208 Netscape/7.02"
+ }, {
+ "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040612 "
+ "Firefox/0.8",
+ "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6; chromeframe/0.0.0.0) "
+ "Gecko/20040612 Firefox/0.8"
+ }, {
+ "Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)",
+ "Mozilla/5.0 (compatible; Konqueror/3.2; Linux; chromeframe/0.0.0.0) "
+ "(KHTML, like Gecko)"
+ }, {
+ "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6h",
+ "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 "
+ "OpenSSL/0.9.6h chromeframe/0.0.0.0",
+ }, {
+ "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.7.10) "
+ "Gecko/20050716 Firefox/1.0.6",
+ "Mozilla/5.0 (X11; U; Linux i686 (x86_64; chromeframe/0.0.0.0); en-US; "
+ "rv:1.7.10) Gecko/20050716 Firefox/1.0.6"
+ }, {
+ "Invalid/1.1 ((((((",
+ "Invalid/1.1 (((((( chromeframe/0.0.0.0",
+ }, {
+ "Invalid/1.1 ()))))",
+ "Invalid/1.1 ( chromeframe/0.0.0.0)))))",
+ }, {
+ "Strange/1.1 ()",
+ "Strange/1.1 ( chromeframe/0.0.0.0)",
+ }
+};
- for (int i = 0; i < arraysize(test_cases); ++i) {
+TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) {
+ for (int i = 0; i < arraysize(user_agent_test_cases); ++i) {
std::string new_ua(
- http_utils::AddChromeFrameToUserAgentValue(test_cases[i].input_));
- EXPECT_EQ(test_cases[i].expected_, new_ua);
+ http_utils::AddChromeFrameToUserAgentValue(
+ user_agent_test_cases[i].input_));
+ EXPECT_EQ(user_agent_test_cases[i].expected_, new_ua);
}
// Now do the same test again, but test that we don't add the chromeframe
// tag if we've already added it.
- for (int i = 0; i < arraysize(test_cases); ++i) {
- std::string ua(test_cases[i].expected_);
+ for (int i = 0; i < arraysize(user_agent_test_cases); ++i) {
+ std::string ua(user_agent_test_cases[i].expected_);
std::string new_ua(http_utils::AddChromeFrameToUserAgentValue(ua));
- EXPECT_EQ(test_cases[i].expected_, new_ua);
+ EXPECT_EQ(user_agent_test_cases[i].expected_, new_ua);
+ }
+}
+
+TEST_F(HtmlUtilUnittest, RemoveChromeFrameFromUserAgentValue) {
+ for (int i = 0; i < arraysize(user_agent_test_cases); ++i) {
+ std::string new_ua(
+ http_utils::RemoveChromeFrameFromUserAgentValue(
+ user_agent_test_cases[i].expected_));
+ EXPECT_EQ(user_agent_test_cases[i].input_, new_ua);
+ }
+
+ // Also test that we don't modify the UA if chromeframe is not present.
+ for (int i = 0; i < arraysize(user_agent_test_cases); ++i) {
+ std::string ua(user_agent_test_cases[i].input_);
+ std::string new_ua(http_utils::RemoveChromeFrameFromUserAgentValue(ua));
+ EXPECT_EQ(user_agent_test_cases[i].input_, new_ua);
}
}
diff --git a/chrome_frame/test/http_negotiate_unittest.cc b/chrome_frame/test/http_negotiate_unittest.cc
index d63b79b..177459c 100644
--- a/chrome_frame/test/http_negotiate_unittest.cc
+++ b/chrome_frame/test/http_negotiate_unittest.cc
@@ -1,16 +1,18 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <atlbase.h>
#include <atlcom.h>
+#include "base/string16.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/win/scoped_bstr.h"
#include "base/win/scoped_comptr.h"
#include "chrome_frame/http_negotiate.h"
#include "chrome_frame/html_utils.h"
+#include "chrome_frame/registry_list_preferences_holder.h"
#include "chrome_frame/test/chrome_frame_test_utils.h"
#include "chrome_frame/utils.h"
#include "gtest/gtest.h"
@@ -65,17 +67,17 @@ TEST_F(HttpNegotiateTest, BeginningTransaction) {
static_cast<IHttpNegotiate*>(
&test_http)))[kBeginningTransactionIndex]);
- std::wstring cf_ua(
+ string16 cf_ua(
ASCIIToWide(http_utils::GetDefaultUserAgentHeaderWithCFTag()));
- std::wstring cf_tag(
+ string16 cf_tag(
ASCIIToWide(http_utils::GetChromeFrameUserAgent()));
- EXPECT_NE(std::wstring::npos, cf_ua.find(L"chromeframe/"));
+ EXPECT_NE(string16::npos, cf_ua.find(L"chromeframe/"));
struct TestCase {
- const std::wstring original_headers_;
- const std::wstring delegate_additional_;
- const std::wstring expected_additional_;
+ const string16 original_headers_;
+ const string16 delegate_additional_;
+ const string16 expected_additional_;
HRESULT delegate_return_value_;
} test_cases[] = {
{ L"Accept: */*\r\n",
@@ -116,12 +118,82 @@ TEST_F(HttpNegotiateTest, BeginningTransaction) {
if (additional) {
// Check against the expected additional headers.
- EXPECT_EQ(test.expected_additional_, std::wstring(additional));
+ EXPECT_EQ(test.expected_additional_, string16(additional));
::CoTaskMemFree(additional);
}
}
}
+TEST_F(HttpNegotiateTest, BeginningTransactionUARemoval) {
+ static const int kBeginningTransactionIndex = 3;
+ CComObjectStackEx<TestHttpNegotiate> test_http;
+ IHttpNegotiate_BeginningTransaction_Fn original =
+ reinterpret_cast<IHttpNegotiate_BeginningTransaction_Fn>(
+ (*reinterpret_cast<void***>(
+ static_cast<IHttpNegotiate*>(
+ &test_http)))[kBeginningTransactionIndex]);
+
+ string16 nocf_ua(
+ ASCIIToWide(http_utils::RemoveChromeFrameFromUserAgentValue(
+ http_utils::GetDefaultUserAgentHeaderWithCFTag())));
+ string16 cf_ua(
+ ASCIIToWide(http_utils::AddChromeFrameToUserAgentValue(
+ WideToASCII(nocf_ua))));
+
+ EXPECT_EQ(string16::npos, nocf_ua.find(L"chromeframe/"));
+ EXPECT_NE(string16::npos, cf_ua.find(L"chromeframe/"));
+
+ string16 ua_url(L"www.withua.com");
+ string16 no_ua_url(L"www.noua.com");
+
+ RegistryListPreferencesHolder& ua_holder =
+ GetUserAgentPreferencesHolderForTesting();
+ ua_holder.AddStringForTesting(no_ua_url);
+
+ struct TestCase {
+ const string16 url_;
+ const string16 original_headers_;
+ const string16 delegate_additional_;
+ const string16 expected_additional_;
+ } test_cases[] = {
+ { ua_url,
+ L"",
+ L"Accept: */*\r\n" + cf_ua + L"\r\n",
+ L"Accept: */*\r\n" + cf_ua + L"\r\n" },
+ { ua_url,
+ L"",
+ L"Accept: */*\r\n" + nocf_ua + L"\r\n",
+ L"Accept: */*\r\n" + cf_ua + L"\r\n" },
+ { no_ua_url,
+ L"",
+ L"Accept: */*\r\n" + cf_ua + L"\r\n",
+ L"Accept: */*\r\n" + nocf_ua + L"\r\n" },
+ { no_ua_url,
+ L"",
+ L"Accept: */*\r\n" + nocf_ua + L"\r\n",
+ L"Accept: */*\r\n" + nocf_ua + L"\r\n" },
+ };
+
+ for (int i = 0; i < arraysize(test_cases); ++i) {
+ TestCase& test = test_cases[i];
+ wchar_t* additional = NULL;
+ test_http.beginning_transaction_ret_ = S_OK;
+ test_http.additional_headers_ = test.delegate_additional_.c_str();
+ HttpNegotiatePatch::BeginningTransaction(original, &test_http,
+ test.url_.c_str(), test.original_headers_.c_str(), 0,
+ &additional);
+ EXPECT_TRUE(additional != NULL);
+
+ if (additional) {
+ // Check against the expected additional headers.
+ EXPECT_EQ(test.expected_additional_, string16(additional))
+ << "Iteration: " << i;
+ ::CoTaskMemFree(additional);
+ }
+ }
+}
+
+
class TestInternetProtocolSink
: public CComObjectRootEx<CComMultiThreadModel>,
public IInternetProtocolSink {
@@ -175,13 +247,13 @@ END_COM_MAP()
return status_;
}
- const std::wstring& last_status_text() const {
+ const string16& last_status_text() const {
return status_text_;
}
protected:
ULONG status_;
- std::wstring status_text_;
+ string16 status_text_;
base::win::ScopedComPtr<IWebBrowser2> browser_;
};
diff --git a/chrome_frame/test/util_unittests.cc b/chrome_frame/test/util_unittests.cc
index 572ef13..9700144 100644
--- a/chrome_frame/test/util_unittests.cc
+++ b/chrome_frame/test/util_unittests.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,6 +10,7 @@
#include "base/win/registry.h"
#include "chrome_frame/navigation_constraints.h"
#include "chrome_frame/test/chrome_frame_test_utils.h"
+#include "chrome_frame/registry_list_preferences_holder.h"
#include "chrome_frame/utils.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -452,6 +453,11 @@ TEST_F(UtilTests, RendererTypeForUrlTest) {
DWORD saved_default_renderer = 0;
config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer);
+ // We need to manually reset the holder between checks.
+ // TODO(robertshield): Remove this when the RegistryWatcher is wired up.
+ RegistryListPreferencesHolder& renderer_type_preferences_holder =
+ GetRendererTypePreferencesHolderForTesting();
+
// Make sure the host is the default renderer.
config_key.WriteValue(kEnableGCFRendererByDefault, static_cast<DWORD>(0));
EXPECT_FALSE(IsGcfDefaultRenderer());
@@ -459,6 +465,7 @@ TEST_F(UtilTests, RendererTypeForUrlTest) {
opt_for_gcf.DeleteValue(kTestFilter); // Just in case this exists
EXPECT_EQ(RENDERER_TYPE_UNDETERMINED, RendererTypeForUrl(kTestUrl));
opt_for_gcf.WriteValue(kTestFilter, L"");
+ renderer_type_preferences_holder.ResetForTesting();
EXPECT_EQ(RENDERER_TYPE_CHROME_OPT_IN_URL, RendererTypeForUrl(kTestUrl));
// Now set GCF as the default renderer.
@@ -466,15 +473,19 @@ TEST_F(UtilTests, RendererTypeForUrlTest) {
EXPECT_TRUE(IsGcfDefaultRenderer());
opt_for_host.DeleteValue(kTestFilter); // Just in case this exists
+ renderer_type_preferences_holder.ResetForTesting();
EXPECT_EQ(RENDERER_TYPE_CHROME_DEFAULT_RENDERER,
RendererTypeForUrl(kTestUrl));
opt_for_host.WriteValue(kTestFilter, L"");
+ renderer_type_preferences_holder.ResetForTesting();
EXPECT_EQ(RENDERER_TYPE_UNDETERMINED, RendererTypeForUrl(kTestUrl));
// Cleanup.
opt_for_gcf.DeleteValue(kTestFilter);
opt_for_host.DeleteValue(kTestFilter);
config_key.WriteValue(kEnableGCFRendererByDefault, saved_default_renderer);
+ renderer_type_preferences_holder.ResetForTesting();
+ RendererTypeForUrl(L"");
}
TEST_F(UtilTests, XUaCompatibleDirectiveTest) {