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

Side by Side Diff: chrome/browser/extensions/service_worker_apitest.cc

Issue 1987393003: Fix ServiceWorkerPushMessagingTest.OnPush. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enable test Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 690
691 std::string value; 691 std::string value;
692 ASSERT_TRUE( 692 ASSERT_TRUE(
693 content::ExecuteScriptAndExtractString(tab, "register();", &value)); 693 content::ExecuteScriptAndExtractString(tab, "register();", &value));
694 EXPECT_EQ("SW controlled", value); 694 EXPECT_EQ("SW controlled", value);
695 695
696 ASSERT_TRUE(RunExtensionTest("service_worker/content_script_fetch")) 696 ASSERT_TRUE(RunExtensionTest("service_worker/content_script_fetch"))
697 << message_; 697 << message_;
698 } 698 }
699 699
700 // Flaky on ChromiumOS bots. http://crbug.com/612673 700 IN_PROC_BROWSER_TEST_F(ServiceWorkerPushMessagingTest, OnPush) {
701 // Flaky on Windows bots. http://crbug.com/612840
702 #if defined(OS_CHROMEOS) || defined(OS_WIN)
703 #define MAYBE_OnPush DISABLED_OnPush
704 #else
705 #define MAYBE_OnPush OnPush
706 #endif
707 IN_PROC_BROWSER_TEST_F(ServiceWorkerPushMessagingTest, MAYBE_OnPush) {
708 const Extension* extension = LoadExtensionWithFlags( 701 const Extension* extension = LoadExtensionWithFlags(
709 test_data_dir_.AppendASCII("service_worker/push_messaging"), kFlagNone); 702 test_data_dir_.AppendASCII("service_worker/push_messaging"), kFlagNone);
710 ASSERT_TRUE(extension); 703 ASSERT_TRUE(extension);
711 GURL extension_url = extension->url(); 704 GURL extension_url = extension->url();
712 705
713 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest(extension_url)); 706 ASSERT_NO_FATAL_FAILURE(GrantNotificationPermissionForTest(extension_url));
714 707
715 GURL url = extension->GetResourceURL("page.html"); 708 GURL url = extension->GetResourceURL("page.html");
716 ui_test_utils::NavigateToURL(browser(), url); 709 ui_test_utils::NavigateToURL(browser(), url);
717 710
718 content::WebContents* web_contents = 711 content::WebContents* web_contents =
719 browser()->tab_strip_model()->GetActiveWebContents(); 712 browser()->tab_strip_model()->GetActiveWebContents();
720 713
721 // Start the ServiceWorker. 714 // Start the ServiceWorker.
722 ExtensionTestMessageListener ready_listener("SERVICE_WORKER_READY", false); 715 ExtensionTestMessageListener ready_listener("SERVICE_WORKER_READY", false);
723 ready_listener.set_failure_message("SERVICE_WORKER_FAILURE"); 716 ready_listener.set_failure_message("SERVICE_WORKER_FAILURE");
724 const char* kScript = "window.runServiceWorker()"; 717 const char* kScript = "window.runServiceWorker()";
725 EXPECT_TRUE(content::ExecuteScript(web_contents->GetMainFrame(), kScript)); 718 EXPECT_TRUE(content::ExecuteScript(web_contents->GetMainFrame(), kScript));
726 EXPECT_TRUE(ready_listener.WaitUntilSatisfied()); 719 EXPECT_TRUE(ready_listener.WaitUntilSatisfied());
727 720
728 PushMessagingAppIdentifier app_identifier = 721 PushMessagingAppIdentifier app_identifier =
729 GetAppIdentifierForServiceWorkerRegistration(0LL, extension_url); 722 GetAppIdentifierForServiceWorkerRegistration(0LL, extension_url);
730 ASSERT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 723 ASSERT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
731 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 724 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
732 725
726 base::RunLoop run_loop;
733 // Send a push message via gcm and expect the ServiceWorker to receive it. 727 // Send a push message via gcm and expect the ServiceWorker to receive it.
734 ExtensionTestMessageListener push_message_listener("OK", false); 728 ExtensionTestMessageListener push_message_listener("OK", false);
735 push_message_listener.set_failure_message("FAIL"); 729 push_message_listener.set_failure_message("FAIL");
736 gcm::IncomingMessage message; 730 gcm::IncomingMessage message;
737 message.sender_id = "1234567890"; 731 message.sender_id = "1234567890";
738 message.raw_data = "testdata"; 732 message.raw_data = "testdata";
739 message.decrypted = true; 733 message.decrypted = true;
734 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure());
740 push_service()->OnMessage(app_identifier.app_id(), message); 735 push_service()->OnMessage(app_identifier.app_id(), message);
741 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied()); 736 EXPECT_TRUE(push_message_listener.WaitUntilSatisfied());
737 run_loop.Run(); // Wait until the message is handled by push service.
742 } 738 }
743 739
744 } // namespace extensions 740 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698