Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc

Issue 2287213002: Ensure loading PDFs doesn't generate 2 http requests (Closed)
Patch Set: Ensure loading PDFs doesn't generate 2 http requests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc
diff --git a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc
index ec1c0ca9e86871e5f663330d45dbe4df1bdb69c1..71d705c01009a179588047d754dea274fbfa536f 100644
--- a/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc
+++ b/extensions/browser/guest_view/mime_handler_view/mime_handler_view_browsertest.cc
@@ -5,9 +5,11 @@
#include "base/base_paths.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
+#include "base/run_loop.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/guest_view/browser/test_guest_view_manager.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/extension_registry.h"
@@ -16,6 +18,8 @@
#include "extensions/browser/guest_view/mime_handler_view/test_mime_handler_view_guest.h"
#include "extensions/test/result_catcher.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/url_request/url_request_filter.h"
+#include "net/url_request/url_request_interceptor.h"
using extensions::ExtensionsAPIClient;
using extensions::MimeHandlerViewGuest;
@@ -28,6 +32,59 @@ using guest_view::TestGuestViewManagerFactory;
// The test extension id is set by the key value in the manifest.
const char* kExtensionId = "oickdpebdnfbgkcaoklfcdhjniefkcji";
+// Counts the number of URL requests made for a given URL.
+class URLRequestCounter {
+ public:
+ URLRequestCounter(const GURL& url) : url_(url), count_(0) {
+ base::RunLoop run_loop;
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&URLRequestCounter::AddInterceptor, base::Unretained(this)),
+ run_loop.QuitClosure());
+ run_loop.Run();
+ }
+
+ ~URLRequestCounter() {
+ base::RunLoop run_loop;
+ content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(&URLRequestCounter::RemoveInterceptor,
+ base::Unretained(this)),
+ run_loop.QuitClosure());
+ run_loop.Run();
+ }
+
+ int count() { return count_; }
+
+ private:
+ class SimpleRequestInterceptor : public net::URLRequestInterceptor {
+ public:
+ SimpleRequestInterceptor(int* count) : count_(count) {}
+
+ // URLRequestInterceptor implementation:
+ net::URLRequestJob* MaybeInterceptRequest(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const override {
+ (*count_)++;
+ return nullptr;
+ }
+
+ int* count_;
Sam McNally 2016/08/30 03:04:28 private:
raymes 2016/08/30 07:32:54 Done.
+ };
+
+ void AddInterceptor() {
+ net::URLRequestFilter::GetInstance()->AddUrlInterceptor(
+ url_, base::WrapUnique(new SimpleRequestInterceptor(&count_)));
Sam McNally 2016/08/30 03:04:28 base::MakeUnique<SimpleRequestInterceptor>(&count_
raymes 2016/08/30 07:32:54 Done.
+ }
+
+ void RemoveInterceptor() {
+ net::URLRequestFilter::GetInstance()->RemoveUrlHandler(url_);
+ }
+
+ GURL url_;
Sam McNally 2016/08/30 03:04:28 const
raymes 2016/08/30 07:32:54 Done.
+ int count_;
Sam McNally 2016/08/30 03:04:28 You're reading and writing |count_| on different t
raymes 2016/08/30 07:32:54 Done - shifted the code around as discussed.
+};
Sam McNally 2016/08/30 03:04:28 DISALLOW_COPY_AND_ASSIGN
raymes 2016/08/30 07:32:54 Done.
+
class MimeHandlerViewTest : public ExtensionApiTest {
public:
MimeHandlerViewTest() {
@@ -36,6 +93,14 @@ class MimeHandlerViewTest : public ExtensionApiTest {
~MimeHandlerViewTest() override {}
+ void SetUpOnMainThread() override {
+ ExtensionApiTest::SetUpOnMainThread();
+
+ StartEmbeddedTestServer();
Sam McNally 2016/08/30 03:04:28 No ASSERT_TRUE()?
raymes 2016/08/30 07:32:54 Done.
+ embedded_test_server()->ServeFilesFromDirectory(
+ test_data_dir_.AppendASCII("mime_handler_view"));
+ }
+
// TODO(paulmeyer): This function is implemented over and over by the
// different GuestView test classes. It really needs to be refactored out to
// some kind of GuestViewTest base class.
@@ -84,10 +149,6 @@ class MimeHandlerViewTest : public ExtensionApiTest {
}
void RunTest(const std::string& path) {
- ASSERT_TRUE(StartEmbeddedTestServer());
- embedded_test_server()->ServeFilesFromDirectory(
- test_data_dir_.AppendASCII("mime_handler_view"));
-
RunTestWithUrl(embedded_test_server()->GetURL("/" + path));
}
@@ -156,3 +217,11 @@ IN_PROC_BROWSER_TEST_F(MimeHandlerViewTest, ResizeBeforeAttach) {
CHECK_EQ(guest_size.width(), 500);
CHECK_EQ(guest_size.height(), 400);
}
+
+// Regression test for crbug.com/587709.
+IN_PROC_BROWSER_TEST_F(MimeHandlerViewTest, SingleRequest) {
+ GURL url(embedded_test_server()->GetURL("/testBasic.csv"));
+ URLRequestCounter request_counter(url);
+ RunTest("testBasic.csv");
+ EXPECT_EQ(1, request_counter.count());
+}
« no previous file with comments | « no previous file | extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698