// 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 "chrome_frame/test/mock_ie_event_sink_actions.h" #include "chrome_frame/test/mock_ie_event_sink_test.h" #include "base/rand_util.h" namespace chrome_frame_test { class TestData { public: TestData(const std::string& value, bool in_header, LoadedInRenderer expected) : value_(value), in_header_(in_header), expected_(expected), name_(base::IntToString(base::RandInt(0, 1000))) { } LoadedInRenderer GetExpectedRenderer() const { return expected_; } std::wstring GetPath() const { return ASCIIToWide("/" + name_); } std::wstring GetUrl(MockWebServer* server_mock) const { return server_mock->Resolve(ASCIIToWide(name_)); } void ExpectOnServer(MockWebServer* server_mock) const { EXPECT_CALL(*server_mock, Get(testing::_, GetPath(), testing::_)) .Times(testing::AnyNumber()) .WillRepeatedly(SendFast(GetHeaders(), GetHtml())); } std::string GetHeaders() const { std::ostringstream headers; headers << "HTTP/1.1 200 OK\r\n" << "Connection: close\r\n" << "Content-Type: text/html\r\n" << "Cache-Control: no-cache\r\n"; if (in_header_) { headers << "X-UA-COMPATIBLE: " << value_ << "\r\n"; } return headers.str(); } std::string GetHtml() const { std::ostringstream html; html << "
"; if (!in_header_) { html << ""; } html << "This is some text."; return html.str(); } private: LoadedInRenderer expected_; std::string name_; std::string value_; bool in_header_; }; // Determines the major version of the installed IE // Returns -1 in case of failure, 0 if the version is newer than currently known int GetIEMajorVersion() { switch (GetInstalledIEVersion()) { case IE_6: return 6; case IE_7: return 7; case IE_8: return 8; case IE_9: return 9; case IE_10: return 10; case IE_INVALID: case NON_IE: case IE_UNSUPPORTED: ADD_FAILURE() << "Failed to detect IE version."; return -1; default: return 0; } } int LowVersion() { int ie_version = GetIEMajorVersion(); switch (ie_version) { case -1: case 0: return 5; default: return ie_version - 1; } } int HighVersion() { int ie_version = GetIEMajorVersion(); switch (ie_version) { case -1: case 0: return 1000; default: return ie_version + 1; } } int EqualVersion() { int ie_version = GetIEMajorVersion(); switch (ie_version) { case -1: case 0: return 1000; default: return ie_version; } } std::string HeaderValue(int ie_version) { if (ie_version == -1) { return "IE=8; Chrome=1"; } else { return std::string("IE=8; Chrome=IE") + base::IntToString(ie_version); } } std::string CorruptHeaderValue(int ie_version) { return HeaderValue(ie_version) + ".0"; } std::string LongHeaderValue(int ie_version) { std::string long_value = HeaderValue(ie_version) + "; " + std::string(256, 'a') + "=bbb"; DCHECK_GT(long_value.length(), 256u); DCHECK_LT(long_value.length(), 512u); return long_value; } class HeaderTest : public MockIEEventSinkTest, public testing::TestWithParam