url_request_context->set_sdch_manager(sdch_manager_.get());
}
+ // Attempt to add a dictionary to the manager; returns whether or not
+ // the attempt succeeded.
+ bool AddSdchDictionary(const std::string& dictionary_text,
+ const GURL& gurl) {
+ std::string list;
+ sdch_manager_->GetAvailDictionaryList(gurl, &list);
+ sdch_manager_->AddSdchDictionary(dictionary_text, gurl);
+ std::string list2;
+ sdch_manager_->GetAvailDictionaryList(gurl, &list2);
+
+ // The list of hashes should change iff the addition succeeds.
+ return (list != list2);
+ }
+
MockFilterContext* filter_context() { return filter_context_.get(); }
- std::string NewSdchCompressedData(const std::string dictionary);
+ std::string NewSdchCompressedData(const std::string dictionary) {
+ std::string client_hash;
+ std::string server_hash;
+ SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
+
+ // Build compressed data that refers to our dictionary.
+ std::string compressed(server_hash);
+ compressed.append("\0", 1);
+ compressed.append(vcdiff_compressed_data_);
+ return compressed;
+ }
const std::string test_vcdiff_dictionary_;
const std::string vcdiff_compressed_data_;
scoped_ptr<MockFilterContext> filter_context_;
};
-std::string SdchFilterTest::NewSdchCompressedData(
- const std::string dictionary) {
- std::string client_hash;
- std::string server_hash;
- SdchManager::GenerateHash(dictionary, &client_hash, &server_hash);
-
- // Build compressed data that refers to our dictionary.
- std::string compressed(server_hash);
- compressed.append("\0", 1);
- compressed.append(vcdiff_compressed_data_);
- return compressed;
-}
-
//------------------------------------------------------------------------------
filter_context()->SetURL(GURL(url_string));
scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
+ // With no input data, try to read output.
+ int output_bytes_or_buffer_size = sizeof(output_buffer);
+ Filter::FilterStatus status = filter->ReadData(output_buffer,
+ &output_bytes_or_buffer_size);
+
+ EXPECT_EQ(0, output_bytes_or_buffer_size);
+ EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
+}
+
+// Make sure that the filter context has everything that might be
+// nuked from it during URLRequest teardown before the SdchFilter
+// destructor.
+TEST_F(SdchFilterTest, SparseContextOk) {
+ std::vector<Filter::FilterType> filter_types;
+ filter_types.push_back(Filter::FILTER_TYPE_SDCH);
+ char output_buffer[20];
+ std::string url_string("http://ignore.com");
+ filter_context()->SetURL(GURL(url_string));
+ scoped_ptr<Filter> filter(Filter::Factory(filter_types, *filter_context()));
// With no input data, try to read output.
int output_bytes_or_buffer_size = sizeof(output_buffer);
EXPECT_EQ(0, output_bytes_or_buffer_size);
EXPECT_EQ(Filter::FILTER_NEED_MORE_DATA, status);
+
+ // Partially tear down context. Anything that goes through request()
+ // without checking it for null in the URLRequestJob::HttpFilterContext
+ // implementation is suspect. Everything that does check it for null should
+ // return null. This is to test for incorrectly relying on filter_context()
+ // from the SdchFilter destructor.
+ filter_context()->NukeUnstableInterfaces();
}
TEST_F(SdchFilterTest, PassThroughWhenTentative) {
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
// Check we can't add it twice.
- EXPECT_FALSE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_FALSE(AddSdchDictionary(dictionary, url));
const std::string kSampleDomain2 = "sdchtest2.com";
std::string url_string2 = "http://" + kSampleDomain2;
GURL url2(url_string2);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary2, url2));
+ EXPECT_TRUE(AddSdchDictionary(dictionary2, url2));
}
}
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
// Create a dictionary with a path restriction, by prefixing dictionary.
const std::string path("/special_path/bin");
std::string dictionary_with_path("Path: " + path + "\n");
dictionary_with_path.append(dictionary);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_path, url));
+ GURL url2(url_string + path);
+ EXPECT_TRUE(AddSdchDictionary(dictionary_with_path, url2));
std::string compressed_for_path(NewSdchCompressedData(dictionary_with_path));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
-
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
// Create a dictionary with a port restriction, by prefixing old dictionary.
const std::string port("502");
std::string dictionary_with_port("Port: " + port + "\n");
dictionary_with_port.append("Port: 80\n"); // Add default port.
dictionary_with_port.append(dictionary);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary_with_port,
- GURL(url_string + ":" + port)));
+ EXPECT_TRUE(AddSdchDictionary(dictionary_with_port,
+ GURL(url_string + ":" + port)));
std::string compressed_for_port(NewSdchCompressedData(dictionary_with_port));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string sdch_compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string sdch_compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string sdch_compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string sdch_compressed(NewSdchCompressedData(dictionary));
std::string url_string = "http://" + kSampleDomain;
GURL url(url_string);
- EXPECT_TRUE(sdch_manager_->AddSdchDictionary(dictionary, url));
+ EXPECT_TRUE(AddSdchDictionary(dictionary, url));
std::string sdch_compressed(NewSdchCompressedData(dictionary));