summaryrefslogtreecommitdiffstats
path: root/chrome/test/nacl
diff options
context:
space:
mode:
authorjvoung <jvoung@chromium.org>2014-08-30 14:47:59 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-30 21:50:49 +0000
commitefd4b3c8968ae61cdfcdbce0f8068e98b5cea6ff (patch)
treee88cc2051a8f9f13a8b09ddbef19db7e6cf0b6f7 /chrome/test/nacl
parent00b31698ea813d2769d7a4f0f0442db203571b07 (diff)
downloadchromium_src-efd4b3c8968ae61cdfcdbce0f8068e98b5cea6ff.zip
chromium_src-efd4b3c8968ae61cdfcdbce0f8068e98b5cea6ff.tar.gz
chromium_src-efd4b3c8968ae61cdfcdbce0f8068e98b5cea6ff.tar.bz2
Retry Set RequestContextObject for PNaCl pexe fetches, to fix On-Demand update.
There was a race condition in the added test check in the previous attempt. That made the test Super Flaky. This is more noticeable in the Release builds than the Debug build that I was working with. (see https://codereview.chromium.org/471233003/) With a Release build I was able to repro the flakiness (40% failure over 200 runs). After the fix, I tested 500 runs and the success rate is now 100%. I can't say it won't flake for other reasons, but this fixes the main flake that was introduced. Historically, the test does ocassionally need to be retried due to timeouts, according to the bot log history. We may want to split the CORS and the non-CORS test case to see if that will help w/ timeouts. I didn't want to do that for this patch, since it would get much more complicated and this is intended for merging to M38. Retry with the race condition fixed. Also re-enable the test since it got disabled by another CL for being flaky. BUG=401755 BUG=315328 Review URL: https://codereview.chromium.org/524683002 Cr-Commit-Position: refs/heads/master@{#292807}
Diffstat (limited to 'chrome/test/nacl')
-rw-r--r--chrome/test/nacl/pnacl_header_test.cc35
-rw-r--r--chrome/test/nacl/pnacl_header_test.h27
2 files changed, 57 insertions, 5 deletions
diff --git a/chrome/test/nacl/pnacl_header_test.cc b/chrome/test/nacl/pnacl_header_test.cc
index 87727a9..ddb2662 100644
--- a/chrome/test/nacl/pnacl_header_test.cc
+++ b/chrome/test/nacl/pnacl_header_test.cc
@@ -12,16 +12,36 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/nacl/nacl_browsertest_util.h"
+#include "content/public/browser/resource_dispatcher_host.h"
#include "content/public/browser/web_contents.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
+#include "net/url_request/url_request.h"
using net::test_server::BasicHttpResponse;
using net::test_server::EmbeddedTestServer;
using net::test_server::HttpRequest;
using net::test_server::HttpResponse;
+void TestDispatcherHostDelegate::RequestBeginning(
+ net::URLRequest* request,
+ content::ResourceContext* resource_context,
+ content::AppCacheService* appcache_service,
+ content::ResourceType resource_type,
+ ScopedVector<content::ResourceThrottle>* throttles) {
+ // This checks the same condition as the one for PNaCl in
+ // AppendComponentUpdaterThrottles.
+ if (resource_type == content::RESOURCE_TYPE_OBJECT) {
+ const net::HttpRequestHeaders& headers = request->extra_request_headers();
+ std::string accept_headers;
+ if (headers.GetHeader("Accept", &accept_headers)) {
+ if (accept_headers.find("application/x-pnacl") != std::string::npos)
+ found_pnacl_header_ = true;
+ }
+ }
+}
+
PnaclHeaderTest::PnaclHeaderTest() : noncors_loads_(0), cors_loads_(0) {}
PnaclHeaderTest::~PnaclHeaderTest() {}
@@ -41,6 +61,7 @@ void PnaclHeaderTest::StartServer() {
void PnaclHeaderTest::RunLoadTest(const std::string& url,
int expected_noncors,
int expected_cors) {
+ content::ResourceDispatcherHost::Get()->SetDelegate(&test_delegate_);
StartServer();
LoadTestMessageHandler handler;
content::JavascriptTestObserver observer(
@@ -57,12 +78,17 @@ void PnaclHeaderTest::RunLoadTest(const std::string& url,
base::ScopedPathOverride component_dir(chrome::DIR_PNACL_COMPONENT);
ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(url));
+
// Wait until the NMF and pexe are also loaded, not just the HTML.
// Do this by waiting till the LoadTestMessageHandler responds.
EXPECT_TRUE(observer.Run()) << handler.error_message();
+
+ // Now check the expectations.
EXPECT_TRUE(handler.test_passed()) << "Test failed.";
EXPECT_EQ(expected_noncors, noncors_loads_);
EXPECT_EQ(expected_cors, cors_loads_);
+
+ content::ResourceDispatcherHost::Get()->SetDelegate(NULL);
}
scoped_ptr<HttpResponse> PnaclHeaderTest::WatchForPexeFetch(
@@ -81,14 +107,14 @@ scoped_ptr<HttpResponse> PnaclHeaderTest::WatchForPexeFetch(
if (absolute_url.path().find(".pexe") == std::string::npos)
return scoped_ptr<HttpResponse>();
- // For pexe files, check for the special Accept header.
- // This must match whatever is in:
- // ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc
+ // For pexe files, check for the special Accept header,
+ // along with the expected ResourceType of the URL request.
EXPECT_NE(0U, request.headers.count("Accept"));
std::map<std::string, std::string>::const_iterator it =
request.headers.find("Accept");
EXPECT_NE(std::string::npos, it->second.find("application/x-pnacl"));
EXPECT_NE(std::string::npos, it->second.find("*/*"));
+ EXPECT_TRUE(test_delegate_.found_pnacl_header());
// Also make sure that other headers like CORS-related headers
// are preserved when injecting the special Accept header.
@@ -109,8 +135,7 @@ scoped_ptr<HttpResponse> PnaclHeaderTest::WatchForPexeFetch(
return http_response.PassAs<HttpResponse>();
}
-// This test is flaky. See http://crbug.com/315328.
-IN_PROC_BROWSER_TEST_F(PnaclHeaderTest, DISABLED_TestHasPnaclHeader) {
+IN_PROC_BROWSER_TEST_F(PnaclHeaderTest, TestHasPnaclHeader) {
// Load 2 pexes, one same origin and one cross orgin.
RunLoadTest("/nacl/pnacl_request_header/pnacl_request_header.html", 1, 1);
}
diff --git a/chrome/test/nacl/pnacl_header_test.h b/chrome/test/nacl/pnacl_header_test.h
index 9134925..6c75fdc 100644
--- a/chrome/test/nacl/pnacl_header_test.h
+++ b/chrome/test/nacl/pnacl_header_test.h
@@ -8,6 +8,8 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/resource_dispatcher_host_delegate.h"
+#include "content/public/common/resource_type.h"
namespace base {
class FilePath;
@@ -20,6 +22,30 @@ class HttpResponse;
}
}
+using content::ResourceDispatcherHostDelegate;
+
+class TestDispatcherHostDelegate : public ResourceDispatcherHostDelegate {
+ public:
+ explicit TestDispatcherHostDelegate()
+ : ResourceDispatcherHostDelegate(), found_pnacl_header_(false) {}
+
+ virtual ~TestDispatcherHostDelegate() {}
+
+ virtual void RequestBeginning(
+ net::URLRequest* request,
+ content::ResourceContext* resource_context,
+ content::AppCacheService* appcache_service,
+ content::ResourceType resource_type,
+ ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;
+
+ bool found_pnacl_header() const { return found_pnacl_header_; }
+
+ private:
+ bool found_pnacl_header_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestDispatcherHostDelegate);
+};
+
class PnaclHeaderTest : public InProcessBrowserTest {
public:
PnaclHeaderTest();
@@ -40,6 +66,7 @@ class PnaclHeaderTest : public InProcessBrowserTest {
int noncors_loads_;
int cors_loads_;
+ TestDispatcherHostDelegate test_delegate_;
DISALLOW_COPY_AND_ASSIGN(PnaclHeaderTest);
};