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

Side by Side Diff: content/browser/background_sync/background_sync_browsertest.cc

Issue 1471763003: [BackgroundSync] Only allow SyncManager.register to occur from main frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split
Patch Set: Address comments from PS6 Created 5 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 20 matching lines...) Expand all
31 #include "net/test/embedded_test_server/embedded_test_server.h" 31 #include "net/test/embedded_test_server/embedded_test_server.h"
32 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
33 33
34 using net::NetworkChangeNotifier; 34 using net::NetworkChangeNotifier;
35 35
36 namespace content { 36 namespace content {
37 37
38 namespace { 38 namespace {
39 39
40 const char kDefaultTestURL[] = "/background_sync/test.html"; 40 const char kDefaultTestURL[] = "/background_sync/test.html";
41 const char kEmptyURL[] = "/background_sync/empty.html";
42 const char kRegisterSyncURL[] = "/background_sync/register_sync.html";
41 43
42 const char kSuccessfulOperationPrefix[] = "ok - "; 44 const char kSuccessfulOperationPrefix[] = "ok - ";
43 45
44 std::string BuildScriptString(const std::string& function, 46 std::string BuildScriptString(const std::string& function,
45 const std::string& argument) { 47 const std::string& argument) {
46 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str()); 48 return base::StringPrintf("%s('%s');", function.c_str(), argument.c_str());
47 } 49 }
48 50
49 std::string BuildExpectedResult(const std::string& tag, 51 std::string BuildExpectedResult(const std::string& tag,
50 const std::string& action) { 52 const std::string& action) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 bool GetRegistrationOneShot(const std::string& tag); 183 bool GetRegistrationOneShot(const std::string& tag);
182 bool GetRegistrationOneShotFromServiceWorker(const std::string& tag); 184 bool GetRegistrationOneShotFromServiceWorker(const std::string& tag);
183 bool MatchRegistrations(const std::string& script_result, 185 bool MatchRegistrations(const std::string& script_result,
184 const std::vector<std::string>& expected_tags); 186 const std::vector<std::string>& expected_tags);
185 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags); 187 bool GetRegistrationsOneShot(const std::vector<std::string>& expected_tags);
186 bool GetRegistrationsOneShotFromServiceWorker( 188 bool GetRegistrationsOneShotFromServiceWorker(
187 const std::vector<std::string>& expected_tags); 189 const std::vector<std::string>& expected_tags);
188 bool CompleteDelayedOneShot(); 190 bool CompleteDelayedOneShot();
189 bool RejectDelayedOneShot(); 191 bool RejectDelayedOneShot();
190 192
193 net::EmbeddedTestServer* https_server() { return https_server_.get(); }
194
191 private: 195 private:
192 scoped_ptr<net::EmbeddedTestServer> https_server_; 196 scoped_ptr<net::EmbeddedTestServer> https_server_;
193 Shell* shell_ = nullptr; 197 Shell* shell_ = nullptr;
194 198
195 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest); 199 DISALLOW_COPY_AND_ASSIGN(BackgroundSyncBrowserTest);
196 }; 200 };
197 201
198 bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) { 202 bool BackgroundSyncBrowserTest::OneShotPending(const std::string& tag) {
199 bool is_pending; 203 bool is_pending;
200 base::RunLoop run_loop; 204 base::RunLoop run_loop;
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 SetMaxSyncAttempts(2); 617 SetMaxSyncAttempts(2);
614 618
615 EXPECT_TRUE(RegisterOneShot("delay")); 619 EXPECT_TRUE(RegisterOneShot("delay"));
616 EXPECT_TRUE(RejectDelayedOneShot()); 620 EXPECT_TRUE(RejectDelayedOneShot());
617 EXPECT_TRUE(PopConsole("ok - delay rejected")); 621 EXPECT_TRUE(PopConsole("ok - delay rejected"));
618 622
619 // Verify that the oneshot is still around and waiting to try again. 623 // Verify that the oneshot is still around and waiting to try again.
620 EXPECT_TRUE(OneShotPending("delay")); 624 EXPECT_TRUE(OneShotPending("delay"));
621 } 625 }
622 626
627 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest, RegisterFromNonMainFrame) {
628 std::string script_result;
629 GURL url = https_server()->GetURL(kEmptyURL);
630 EXPECT_TRUE(
631 RunScript(BuildScriptString("registerOneShotFromLocalFrame", url.spec()),
632 &script_result));
633 EXPECT_EQ(BuildExpectedResult("iframe", "failed to register sync"),
634 script_result);
635 }
636
637 IN_PROC_BROWSER_TEST_F(BackgroundSyncBrowserTest,
638 RegisterFromServiceWorkerWithoutMainFrameHost) {
639 // Start a second https server to use as a second origin.
640 net::EmbeddedTestServer alt_server(net::EmbeddedTestServer::TYPE_HTTPS);
641 alt_server.ServeFilesFromSourceDirectory("content/test/data");
642 ASSERT_TRUE(alt_server.Start());
643
644 std::string script_result;
645 GURL url = alt_server.GetURL(kRegisterSyncURL);
646 EXPECT_TRUE(
647 RunScript(BuildScriptString("registerOneShotFromCrossOriginServiceWorker",
648 url.spec()),
649 &script_result));
650 EXPECT_EQ(BuildExpectedResult("worker", "failed to register sync"),
651 script_result);
652 }
653
623 } // namespace content 654 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/background_sync/background_sync_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698