Commit 6e310446 authored by michaeln@google.com's avatar michaeln@google.com

No longer check for a specific mime-type on appcache manifest files. The spec...

No longer check for a specific mime-type on appcache manifest files. The spec was recently changed in this way.

BUG=103939
TEST=appcache_update_job_unittest.cc
Review URL: http://codereview.chromium.org/8566020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111000 0039d316-1c4b-4281-b951-d872f2087c98
parent 74819e8c
...@@ -14,8 +14,6 @@ using WebKit::WebConsoleMessage; ...@@ -14,8 +14,6 @@ using WebKit::WebConsoleMessage;
namespace appcache { namespace appcache {
const char kManifestMimeType[] = "text/cache-manifest";
const char kHttpScheme[] = "http"; const char kHttpScheme[] = "http";
const char kHttpsScheme[] = "https"; const char kHttpsScheme[] = "https";
const char kHttpGETMethod[] = "GET"; const char kHttpGETMethod[] = "GET";
......
...@@ -21,7 +21,6 @@ namespace appcache { ...@@ -21,7 +21,6 @@ namespace appcache {
// Defines constants, types, and abstract classes used in the main // Defines constants, types, and abstract classes used in the main
// process and in child processes. // process and in child processes.
extern const char kManifestMimeType[];
static const int kNoHostId = 0; static const int kNoHostId = 0;
static const int64 kNoCacheId = 0; static const int64 kNoCacheId = 0;
......
...@@ -438,17 +438,13 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted( ...@@ -438,17 +438,13 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted(
net::URLRequest* request = fetcher->request(); net::URLRequest* request = fetcher->request();
int response_code = -1; int response_code = -1;
std::string mime_type;
bool is_valid_response_code = false; bool is_valid_response_code = false;
bool is_valid_mime_type = false;
if (request->status().is_success()) { if (request->status().is_success()) {
response_code = request->GetResponseCode(); response_code = request->GetResponseCode();
is_valid_response_code = (response_code / 100 == 2); is_valid_response_code = (response_code / 100 == 2);
request->GetMimeType(&mime_type);
is_valid_mime_type = (mime_type == kManifestMimeType);
} }
if (is_valid_response_code && is_valid_mime_type) { if (is_valid_response_code) {
manifest_data_ = fetcher->manifest_data(); manifest_data_ = fetcher->manifest_data();
manifest_response_info_.reset( manifest_response_info_.reset(
new net::HttpResponseInfo(request->response_info())); new net::HttpResponseInfo(request->response_info()));
...@@ -462,17 +458,9 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted( ...@@ -462,17 +458,9 @@ void AppCacheUpdateJob::HandleManifestFetchCompleted(
update_type_ == UPGRADE_ATTEMPT) { update_type_ == UPGRADE_ATTEMPT) {
service_->storage()->MakeGroupObsolete(group_, this); // async service_->storage()->MakeGroupObsolete(group_, this); // async
} else { } else {
std::string message; const char* kFormatString = "Manifest fetch failed (%d) %s";
if (!is_valid_response_code) { std::string message = base::StringPrintf(kFormatString, response_code,
const char* kFormatString = "Manifest fetch failed (%d) %s"; manifest_url_.spec().c_str());
message = base::StringPrintf(kFormatString, response_code,
manifest_url_.spec().c_str());
} else {
DCHECK(!is_valid_mime_type);
const char* kFormatString = "Invalid manifest mime type (%s) %s";
message = base::StringPrintf(kFormatString, mime_type.c_str(),
manifest_url_.spec().c_str());
}
HandleCacheFailure(message); HandleCacheFailure(message);
} }
} }
...@@ -881,6 +869,9 @@ void AppCacheUpdateJob::BuildUrlFileList(const Manifest& manifest) { ...@@ -881,6 +869,9 @@ void AppCacheUpdateJob::BuildUrlFileList(const Manifest& manifest) {
AddUrlToFileList(GURL(*it), AppCacheEntry::EXPLICIT); AddUrlToFileList(GURL(*it), AppCacheEntry::EXPLICIT);
} }
// TODO(michaeln): Add resources from intercept namepsaces too.
// http://code.google.com/p/chromium/issues/detail?id=101565
const std::vector<FallbackNamespace>& fallbacks = const std::vector<FallbackNamespace>& fallbacks =
manifest.fallback_namespaces; manifest.fallback_namespaces;
for (std::vector<FallbackNamespace>::const_iterator it = fallbacks.begin(); for (std::vector<FallbackNamespace>::const_iterator it = fallbacks.begin();
......
...@@ -89,7 +89,7 @@ class MockHttpServer { ...@@ -89,7 +89,7 @@ class MockHttpServer {
"Cache-Control: no-store\0" "Cache-Control: no-store\0"
"\0"; "\0";
if (path == "/files/wrong-mime-manifest") { if (path == "/files/missing-mime-manifest") {
(*headers) = std::string(ok_headers, arraysize(ok_headers)); (*headers) = std::string(ok_headers, arraysize(ok_headers));
(*body) = "CACHE MANIFEST\n"; (*body) = "CACHE MANIFEST\n";
} else if (path == "/files/bad-manifest") { } else if (path == "/files/bad-manifest") {
...@@ -766,27 +766,39 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -766,27 +766,39 @@ class AppCacheUpdateJobTest : public testing::Test,
WaitForUpdateToFinish(); WaitForUpdateToFinish();
} }
void ManifestWrongMimeTypeTest() { void ManifestMissingMimeTypeTest() {
ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
MakeService(); MakeService();
group_ = new AppCacheGroup( group_ = new AppCacheGroup(
service_.get(), MockHttpServer::GetMockUrl("files/wrong-mime-manifest"), service_.get(),
MockHttpServer::GetMockUrl("files/missing-mime-manifest"),
service_->storage()->NewGroupId()); service_->storage()->NewGroupId());
AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_);
group_->update_job_ = update; group_->update_job_ = update;
AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 33);
MockFrontend* frontend = MakeMockFrontend(); MockFrontend* frontend = MakeMockFrontend();
AppCacheHost* host = MakeHost(1, frontend); AppCacheHost* host = MakeHost(1, frontend);
update->StartUpdate(host, GURL()); host->AssociateCompleteCache(cache);
frontend->SetVerifyProgressEvents(true);
update->StartUpdate(NULL, GURL());
EXPECT_TRUE(update->manifest_fetcher_ != NULL); EXPECT_TRUE(update->manifest_fetcher_ != NULL);
// Set up checks for when update job finishes. // Set up checks for when update job finishes.
do_checks_after_update_finished_ = true; do_checks_after_update_finished_ = true;
expect_group_obsolete_ = false; expect_group_obsolete_ = false;
expect_group_has_cache_ = false; // bad mime type is like a failed request expect_group_has_cache_ = true;
frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), expect_old_cache_ = cache;
CHECKING_EVENT); tested_manifest_ = EMPTY_MANIFEST;
tested_manifest_path_override_ = "files/missing-mime-manifest";
MockFrontend::HostIds ids(1, host->host_id());
frontend->AddExpectedEvent(ids, CHECKING_EVENT);
frontend->AddExpectedEvent(ids, DOWNLOADING_EVENT);
frontend->AddExpectedEvent(ids, PROGRESS_EVENT); // final
frontend->AddExpectedEvent(ids, UPDATE_READY_EVENT);
WaitForUpdateToFinish(); WaitForUpdateToFinish();
} }
...@@ -3267,8 +3279,8 @@ TEST_F(AppCacheUpdateJobTest, ManifestRedirect) { ...@@ -3267,8 +3279,8 @@ TEST_F(AppCacheUpdateJobTest, ManifestRedirect) {
RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest); RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest);
} }
TEST_F(AppCacheUpdateJobTest, ManifestWrongMimeType) { TEST_F(AppCacheUpdateJobTest, ManifestMissingMimeTypeTest) {
RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestWrongMimeTypeTest); RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestMissingMimeTypeTest);
} }
TEST_F(AppCacheUpdateJobTest, ManifestNotFound) { TEST_F(AppCacheUpdateJobTest, ManifestNotFound) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment