Chromium Code Reviews| Index: chrome/browser/services/gcm/push_messaging_browsertest.cc |
| diff --git a/chrome/browser/services/gcm/push_messaging_browsertest.cc b/chrome/browser/services/gcm/push_messaging_browsertest.cc |
| index 42a3221f6ae3aabaead9a909bacc4b692b7b1c6a..0eca486e53fe7ca0ddda8e02441bc05718a1509c 100644 |
| --- a/chrome/browser/services/gcm/push_messaging_browsertest.cc |
| +++ b/chrome/browser/services/gcm/push_messaging_browsertest.cc |
| @@ -32,6 +32,10 @@ |
| #include "content/public/test/browser_test_utils.h" |
| #include "ui/base/window_open_disposition.h" |
| +#if defined(OS_ANDROID) |
| +#include "base/android/build_info.h" |
| +#endif |
| + |
| namespace gcm { |
| namespace { |
| @@ -106,6 +110,18 @@ class UnregistrationCallback { |
| std::string app_id_; |
| }; |
| +// The Push API depends on Web Notifications, which is only available on Android |
| +// Jelly Bean and later, which maps to Android SDK level 16. |
| +bool IsPushSupported() { |
| +#if defined(OS_ANDROID) |
| + if (base::android::BuildInfo::GetInstance()->sdk_int() < 16) { |
| + DVLOG(0) << "The Push API is only supported in Android 4.1 and later."; |
| + return false; |
| + } |
| +#endif |
| + return true; |
| +} |
| + |
| } // namespace |
| class PushMessagingBrowserTest : public InProcessBrowserTest { |
| @@ -116,8 +132,6 @@ class PushMessagingBrowserTest : public InProcessBrowserTest { |
| // InProcessBrowserTest: |
| void SetUpCommandLine(base::CommandLine* command_line) override { |
| command_line->AppendSwitch( |
| - switches::kEnableExperimentalWebPlatformFeatures); |
| - command_line->AppendSwitch( |
| switches::kEnablePushMessagePayload); |
| InProcessBrowserTest::SetUpCommandLine(command_line); |
| @@ -226,6 +240,9 @@ class PushMessagingBadManifestBrowserTest : public PushMessagingBrowserTest { |
| IN_PROC_BROWSER_TEST_F(PushMessagingBadManifestBrowserTest, |
| RegisterFailsNotVisibleMessages) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -253,6 +270,9 @@ void PushMessagingBrowserTest::TryToRegisterSuccessfully( |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| RegisterSuccessNotificationsGranted) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| PushMessagingApplicationId app_id(https_server()->GetURL(""), |
| @@ -263,6 +283,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| RegisterSuccessNotificationsPrompt) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -279,6 +302,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| RegisterFailureNotificationsBlocked) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -294,6 +320,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoManifest) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -314,6 +343,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoManifest) { |
| // TODO(johnme): Test registering from a worker - see https://crbug.com/437298. |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| // An app ID for each Service Worker registration ID we'll use. |
| @@ -370,6 +402,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| @@ -394,6 +429,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| @@ -433,6 +471,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| @@ -474,6 +515,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { |
| #if defined(ENABLE_NOTIFICATIONS) |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| PushEventEnforcesUserVisibleNotification) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| @@ -565,6 +609,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
| #endif |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -575,6 +622,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysGranted) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -592,6 +642,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysGranted) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDenied) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
| @@ -610,6 +663,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDenied) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterSuccess) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| @@ -621,6 +677,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterSuccess) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterNetworkError) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| @@ -634,6 +693,9 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterNetworkError) { |
| } |
| IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterUnknownError) { |
| + if (!IsPushSupported()) |
| + return; |
| + |
| std::string script_result; |
| TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); |
| @@ -646,4 +708,16 @@ IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterUnknownError) { |
| " push server.", script_result); |
| } |
| +IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushUnavailableOnAndroidICS) { |
| + // This test should only be ran on Android ICS to confirm that the Push API |
|
Michael van Ouwerkerk
2015/02/13 11:50:47
nit: 'only run' and 'available'
Peter Beverloo
2015/02/13 12:22:51
Done.
|
| + // is not avialable on that version of Android. |
| + if (IsPushSupported()) |
| + return; |
| + |
| + std::string script_result; |
| + ASSERT_TRUE(RunScript("window.PushManager", &script_result)); |
| + EXPECT_EQ("undefined", script_result); |
| + |
|
Michael van Ouwerkerk
2015/02/13 11:50:47
nit: delete empty line
Peter Beverloo
2015/02/13 12:22:51
Done.
|
| +} |
| + |
| } // namespace gcm |