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

Unified Diff: net/url_request/url_request_unittest.cc

Issue 1366203004: Small fix for URLRequestJobs when entering suspending mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to comments, fix test name/description Created 5 years, 3 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 | « net/url_request/url_request_job.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_unittest.cc
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 72cb56e256be50a96901dc47a68cad2f2cbf6d77..e8f9668b60d94a34768e2cf50f03ec140c6b724d 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -26,6 +26,8 @@
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
+#include "base/power_monitor/power_monitor.h"
+#include "base/power_monitor/power_monitor_source.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
@@ -258,6 +260,21 @@ void TestLoadTimingNoHttpResponse(
}
#endif
+// Test power monitor source that can simulate entering suspend mode. Can't use
+// the one in base/ because it insists on bringing its own MessageLoop.
+class TestPowerMonitorSource : public base::PowerMonitorSource {
+ public:
+ TestPowerMonitorSource() {}
+ ~TestPowerMonitorSource() override {}
+
+ void Suspend() { ProcessPowerEvent(SUSPEND_EVENT); }
+
+ bool IsOnBatteryPowerImpl() override { return false; }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestPowerMonitorSource);
+};
+
// Do a case-insensitive search through |haystack| for |needle|.
bool ContainsString(const std::string& haystack, const char* needle) {
std::string::const_iterator it = std::search(
@@ -3897,6 +3914,27 @@ TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) {
}
}
+// Tests that a request is cancelled while entering suspend mode.
+TEST_F(URLRequestTestHTTP, CancelOnSuspend) {
+ TestPowerMonitorSource* power_monitor_source = new TestPowerMonitorSource();
+ base::PowerMonitor power_monitor(make_scoped_ptr(power_monitor_source));
+ ASSERT_TRUE(test_server_.Start());
+
+ TestDelegate d;
+ // Request that won't complete any time soon.
+ GURL url(test_server_.GetURL("slow?600"));
+ scoped_ptr<URLRequest> r(
+ default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
+ r->Start();
+
+ power_monitor_source->Suspend();
+ // Wait for the suspend notification to cause the request to fail.
+ base::RunLoop().Run();
+ EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
+ EXPECT_TRUE(d.request_failed());
+ EXPECT_EQ(1, default_network_delegate_.completed_requests());
+}
+
TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
ASSERT_TRUE(test_server_.Start());
« no previous file with comments | « net/url_request/url_request_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698