Commit ab1aa836 authored by jianli@chromium.org's avatar jianli@chromium.org

Move GcmApi test cases into separate subdir in order to use RunExtensionTest

Change to use RunExtensionTest which is far less flaky than using RunExtensionSubtest

BUG=177163
TEST=these are tests

Review URL: https://codereview.chromium.org/129113002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243689 0039d316-1c4b-4281-b951-d872f2087c98
parent a618254f
......@@ -13,7 +13,6 @@
namespace {
const char kFunctionsTestExtension[] = "gcm/functions";
const char kEventsExtension[] = "gcm/events";
} // namespace
......@@ -25,6 +24,7 @@ class GcmApiTest : public ExtensionApiTest {
GcmApiTest() : fake_gcm_profile_service_(NULL) {}
protected:
virtual void SetUp() OVERRIDE;
virtual void SetUpOnMainThread() OVERRIDE;
void StartCollecting();
......@@ -32,13 +32,19 @@ class GcmApiTest : public ExtensionApiTest {
const Extension* LoadTestExtension(const std::string& extension_path,
const std::string& page_name);
void WaitUntilIdle();
gcm::FakeGCMProfileService* service() const;
private:
gcm::FakeGCMProfileService* fake_gcm_profile_service_;
};
void GcmApiTest::SetUp() {
// TODO(jianli): Once the GCM API enters stable, remove |channel|.
ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN);
ExtensionApiTest::SetUp();
}
void GcmApiTest::SetUpOnMainThread() {
gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactory(
browser()->profile(), &gcm::FakeGCMProfileService::Build);
......@@ -52,11 +58,6 @@ void GcmApiTest::StartCollecting() {
service()->set_collect(true);
}
void GcmApiTest::WaitUntilIdle() {
base::RunLoop run_loop;
run_loop.RunUntilIdle();
}
gcm::FakeGCMProfileService* GcmApiTest::service() const {
return fake_gcm_profile_service_;
}
......@@ -64,8 +65,6 @@ gcm::FakeGCMProfileService* GcmApiTest::service() const {
const Extension* GcmApiTest::LoadTestExtension(
const std::string& extension_path,
const std::string& page_name) {
// TODO(jianli): Once the GCM API enters stable, remove |channel|.
ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_UNKNOWN);
const Extension* extension =
LoadExtension(test_data_dir_.AppendASCII(extension_path));
if (extension) {
......@@ -75,26 +74,14 @@ const Extension* GcmApiTest::LoadTestExtension(
return extension;
}
// http://crbug.com/177163
#if defined(OS_WIN)
#define MAYBE_RegisterValidation DISABLED_RegisterValidation
#else
#define MAYBE_RegisterValidation RegisterValidation
#endif
IN_PROC_BROWSER_TEST_F(GcmApiTest, MAYBE_RegisterValidation) {
EXPECT_TRUE(RunExtensionSubtest(kFunctionsTestExtension,
"register_validation.html"));
IN_PROC_BROWSER_TEST_F(GcmApiTest, RegisterValidation) {
ASSERT_TRUE(RunExtensionTest("gcm/functions/register_validation"));
}
IN_PROC_BROWSER_TEST_F(GcmApiTest, Register) {
StartCollecting();
const extensions::Extension* extension =
LoadTestExtension(kFunctionsTestExtension, "register.html");
ASSERT_TRUE(extension);
ASSERT_TRUE(RunExtensionTest("gcm/functions/register"));
WaitUntilIdle();
EXPECT_EQ(extension->id(), service()->last_registered_app_id());
// SHA1 of the public key provided in manifest.json.
EXPECT_EQ("26469186F238EE08FA71C38311C6990F61D40DCA",
service()->last_registered_cert());
......@@ -106,23 +93,13 @@ IN_PROC_BROWSER_TEST_F(GcmApiTest, Register) {
sender_ids.end());
}
// http://crbug.com/177163
#if defined(OS_WIN)
#define MAYBE_SendValidation DISABLED_SendValidation
#else
#define MAYBE_SendValidation SendValidation
#endif
IN_PROC_BROWSER_TEST_F(GcmApiTest, MAYBE_SendValidation) {
EXPECT_TRUE(RunExtensionSubtest(kFunctionsTestExtension, "send.html"));
IN_PROC_BROWSER_TEST_F(GcmApiTest, SendValidation) {
ASSERT_TRUE(RunExtensionTest("gcm/functions/send"));
}
IN_PROC_BROWSER_TEST_F(GcmApiTest, SendMessageData) {
StartCollecting();
const extensions::Extension* extension =
LoadTestExtension(kFunctionsTestExtension, "send_message_data.html");
ASSERT_TRUE(extension);
WaitUntilIdle();
ASSERT_TRUE(RunExtensionTest("gcm/functions/send_message_data"));
EXPECT_EQ("destination-id", service()->last_receiver_id());
const gcm::GCMClient::OutgoingMessage& message =
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
onload = function() {
senderIds = ["Sender1", "Sender2"];
chrome.gcm.register(senderIds, function(registrationId) {});
};
{
"manifest_version": 2,
"name": "Test GCM App",
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzXCAvAUOKVNuBGWfaRY6QW1YSs+2EnmERkltllVyk9T6H/a7wkdBAKpvKsEbE9PtjmHrP/Jh/XFX1AdpTFAJ7KsQ55GdyTwUW7iB5HsR4NI6dXewK2ba+vDbtBLytR9msXFpvuVnAsEmLlHf9RGuxczvOEbGXcHkUw0AuzGu72wIDAQAB",
"version": "1.0",
"description": "Tests GCM API",
"background": {
"scripts": ["register.js"]
},
"permissions": ["gcm"]
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.test.runTests([
function testRegister() {
var senderIds = ["Sender1", "Sender2"];
chrome.gcm.register(senderIds, function(registrationId) {
chrome.test.succeed();
});
}
]);
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
onload = function() {
function generateSenderIds(size) {
var senders = [];
for (var i = 0; i < size; i++) {
senders.push("Sender" + i);
}
return senders;
}
function toArrayDefinitionString(senderIds) {
var idsString = "[";
senderIds.forEach(function(element, index) {
if (index > 0) idsString += ", ";
idsString += "\"" + element + "\"";
});
idsString += "]";
return idsString;
}
function registerSuccessfully(senderIds) {
chrome.gcm.register(senderIds, function(registrationId) {
chrome.test.assertEq("" + senderIds.length, registrationId);
chrome.test.succeed();
});
}
function registerInvalidParameters(senderIds) {
try {
chrome.gcm.register(senderIds, function(registrationId) {
chrome.test.fail("Arguments: " + toArrayDefinitionString(senderIds));
});
} catch (e) {
chrome.test.succeed();
};
}
chrome.test.runTests([
function successWithOneSender() {
registerSuccessfully(generateSenderIds(1));
},
function successWithMultipleSenders() {
registerSuccessfully(generateSenderIds(10));
},
function successWithMaxSenders() {
registerSuccessfully(generateSenderIds(100));
},
function failureWithNoSenders() {
registerInvalidParameters([]);
},
function failureWithEmptySenderOnly() {
registerInvalidParameters([""]);
},
function failureWithEmptySender() {
registerInvalidParameters(["good", ""]);
},
function failureWithTooManySenders() {
registerInvalidParameters(generateSenderIds(101));
}
]);
};
{
"manifest_version": 2,
"name": "Test GCM App",
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzXCAvAUOKVNuBGWfaRY6QW1YSs+2EnmERkltllVyk9T6H/a7wkdBAKpvKsEbE9PtjmHrP/Jh/XFX1AdpTFAJ7KsQ55GdyTwUW7iB5HsR4NI6dXewK2ba+vDbtBLytR9msXFpvuVnAsEmLlHf9RGuxczvOEbGXcHkUw0AuzGu72wIDAQAB",
"version": "1.0",
"description": "Tests GCM API",
"background": {
"scripts": ["register_validation.js"]
},
"permissions": ["gcm"]
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function generateSenderIds(size) {
var senders = [];
for (var i = 0; i < size; i++) {
senders.push("Sender" + i);
}
return senders;
}
function toArrayDefinitionString(senderIds) {
var idsString = "[";
senderIds.forEach(function(element, index) {
if (index > 0) idsString += ", ";
idsString += "\"" + element + "\"";
});
idsString += "]";
return idsString;
}
function registerSuccessfully(senderIds) {
chrome.gcm.register(senderIds, function(registrationId) {
chrome.test.assertEq("" + senderIds.length, registrationId);
chrome.test.succeed();
});
}
function registerInvalidParameters(senderIds) {
try {
chrome.gcm.register(senderIds, function(registrationId) {
chrome.test.fail("Arguments: " + toArrayDefinitionString(senderIds));
});
} catch (e) {
chrome.test.succeed();
};
}
chrome.test.runTests([
function successWithOneSender() {
registerSuccessfully(generateSenderIds(1));
},
function successWithMultipleSenders() {
registerSuccessfully(generateSenderIds(10));
},
function successWithMaxSenders() {
registerSuccessfully(generateSenderIds(100));
},
function failureWithNoSenders() {
registerInvalidParameters([]);
},
function failureWithEmptySenderOnly() {
registerInvalidParameters([""]);
},
function failureWithEmptySender() {
registerInvalidParameters(["good", ""]);
},
function failureWithTooManySenders() {
registerInvalidParameters(generateSenderIds(101));
}
]);
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
onload = function() {
function createMessage() {
return {
messageId: "message-id",
destinationId: "destination-id",
timeToLive: 2419200,
data: {
"key1": "value1",
"key2": "value"
}
};
}
function successfulSend(message) {
chrome.gcm.send(message, function(messageId) {
chrome.test.assertEq(message.messageId, messageId);
chrome.test.succeed();
});
}
function unsuccessfulSend(message) {
try {
chrome.gcm.send(message, function(messageId) {
chrome.test.fail(message);
});
} catch(e) {
chrome.test.succeed();
}
}
function scenario(messageMutations, send) {
var message = createMessage();
messageMutations.forEach(function(mutation) {
mutation(message);
});
send(message);
}
function expectSuccessWhen() {
scenario(Array.prototype.slice.call(arguments), successfulSend);
}
function expectFailureWhen() {
scenario(Array.prototype.slice.call(arguments), unsuccessfulSend);
}
chrome.test.runTests([
function successWhenHappyPath() {
expectSuccessWhen(/* no changes to message here */);
},
function successWhenTtlIsZero() {
expectSuccessWhen(function(message) { message.timeToLive = 0; });
},
function successWhenTtlIsMissing() {
expectSuccessWhen(function(message) { delete message.timeToLive; });
},
function failureWhenTtlIsNegative() {
expectFailureWhen(function(message) { message.timeToLive = -1; });
},
function failureWhenTtlIsTooLarge() {
expectFailureWhen(function(message) { message.timeToLive = 24192001; });
},
function failureWhenMessageIdMissing() {
expectFailureWhen(function(message) { delete message.messageId; });
},
function failureWhenMessageIdIsEmpty() {
expectFailureWhen(function(message) { message.messageId = ""; });
},
function failureWhenDestinationIdMissing() {
expectFailureWhen(function(message) { delete message.destinationId; });
},
function failureWhenDestinationIdIsEmpty() {
expectFailureWhen(function(message) { message.destinationId = ""; });
},
function failureWhenDataIsMissing() {
expectFailureWhen(function(message) { delete message.data; });
},
function failureWhenDataIsEmpty() {
expectFailureWhen(function(message) { message.data = {}; });
},
function failureWhenDataKeyIsEmpty() {
expectFailureWhen(function(message) { message.data[""] = "value"; });
},
function successWhenDataKeyHasGoogDotInIt() {
expectSuccessWhen(function(message) {
message.data["something.goog."] = "value";
});
},
function failureWhenDataKeyIsGoogDot() {
expectFailureWhen(function(message) { message.data["goog."] = "value"; });
},
function failureWhenDataKeyIsGoogDotPrefixed() {
expectFailureWhen(function(message) {
message.data["goog.something"] = "value";
});
},
function successWhenDataKeyHasGoogleInIt() {
expectSuccessWhen(function(message) {
message.data["somthing.google"] = "value";
});
},
function failureWhenDataKeyIsGoogle() {
expectFailureWhen(function(message) {
message.data["google"] = "value";
});
},
function failureWhenDataKeyIsGooglePrefixed() {
expectFailureWhen(function(message) {
message.data["googleSomething"] = "value";
});
},
function failureWhenMessageIsTooLarge() {
expectFailureWhen(function(message) {
function generateString(base, len) {
// Generates a string of size |len| by concatenating |base| multiple
// times and trimming to |len|.
while (base.length < len) base += base;
return base.substring(0, len);
}
var source = "abcdefghijklmnopqrstuvwxyz";
// Creates 8 * (256 + 256) == 4096 bytes of message data which together
// with data put in by default is more than allowed max.
var entries = 8;
while (entries > 0) {
var s = generateString(source + entries, 256);
message.data[s] = s;
--entries;
}
});
}
]);
};
......@@ -4,5 +4,8 @@
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzXCAvAUOKVNuBGWfaRY6QW1YSs+2EnmERkltllVyk9T6H/a7wkdBAKpvKsEbE9PtjmHrP/Jh/XFX1AdpTFAJ7KsQ55GdyTwUW7iB5HsR4NI6dXewK2ba+vDbtBLytR9msXFpvuVnAsEmLlHf9RGuxczvOEbGXcHkUw0AuzGu72wIDAQAB",
"version": "1.0",
"description": "Tests GCM API",
"background": {
"scripts": ["send.js"]
},
"permissions": ["gcm"]
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function createMessage() {
return {
messageId: "message-id",
destinationId: "destination-id",
timeToLive: 2419200,
data: {
"key1": "value1",
"key2": "value"
}
};
}
function successfulSend(message) {
chrome.gcm.send(message, function(messageId) {
chrome.test.assertEq(message.messageId, messageId);
chrome.test.succeed();
});
}
function unsuccessfulSend(message) {
try {
chrome.gcm.send(message, function(messageId) {
chrome.test.fail(message);
});
} catch(e) {
chrome.test.succeed();
}
}
function scenario(messageMutations, send) {
var message = createMessage();
messageMutations.forEach(function(mutation) {
mutation(message);
});
send(message);
}
function expectSuccessWhen() {
scenario(Array.prototype.slice.call(arguments), successfulSend);
}
function expectFailureWhen() {
scenario(Array.prototype.slice.call(arguments), unsuccessfulSend);
}
chrome.test.runTests([
function successWhenHappyPath() {
expectSuccessWhen(/* no changes to message here */);
},
function successWhenTtlIsZero() {
expectSuccessWhen(function(message) { message.timeToLive = 0; });
},
function successWhenTtlIsMissing() {
expectSuccessWhen(function(message) { delete message.timeToLive; });
},
function failureWhenTtlIsNegative() {
expectFailureWhen(function(message) { message.timeToLive = -1; });
},
function failureWhenTtlIsTooLarge() {
expectFailureWhen(function(message) { message.timeToLive = 24192001; });
},
function failureWhenMessageIdMissing() {
expectFailureWhen(function(message) { delete message.messageId; });
},
function failureWhenMessageIdIsEmpty() {
expectFailureWhen(function(message) { message.messageId = ""; });
},
function failureWhenDestinationIdMissing() {
expectFailureWhen(function(message) { delete message.destinationId; });
},
function failureWhenDestinationIdIsEmpty() {
expectFailureWhen(function(message) { message.destinationId = ""; });
},
function failureWhenDataIsMissing() {
expectFailureWhen(function(message) { delete message.data; });
},
function failureWhenDataIsEmpty() {
expectFailureWhen(function(message) { message.data = {}; });
},
function failureWhenDataKeyIsEmpty() {
expectFailureWhen(function(message) { message.data[""] = "value"; });
},
function successWhenDataKeyHasGoogDotInIt() {
expectSuccessWhen(function(message) {
message.data["something.goog."] = "value";
});
},
function failureWhenDataKeyIsGoogDot() {
expectFailureWhen(function(message) { message.data["goog."] = "value"; });
},
function failureWhenDataKeyIsGoogDotPrefixed() {
expectFailureWhen(function(message) {
message.data["goog.something"] = "value";
});
},
function successWhenDataKeyHasGoogleInIt() {
expectSuccessWhen(function(message) {
message.data["somthing.google"] = "value";
});
},
function failureWhenDataKeyIsGoogle() {
expectFailureWhen(function(message) {
message.data["google"] = "value";
});
},
function failureWhenDataKeyIsGooglePrefixed() {
expectFailureWhen(function(message) {
message.data["googleSomething"] = "value";
});
},
function failureWhenMessageIsTooLarge() {
expectFailureWhen(function(message) {
function generateString(base, len) {
// Generates a string of size |len| by concatenating |base| multiple
// times and trimming to |len|.
while (base.length < len) base += base;
return base.substring(0, len);
}
var source = "abcdefghijklmnopqrstuvwxyz";
// Creates 8 * (256 + 256) == 4096 bytes of message data which together
// with data put in by default is more than allowed max.
var entries = 8;
while (entries > 0) {
var s = generateString(source + entries, 256);
message.data[s] = s;
--entries;
}
});
}
]);
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
onload = function() {
var message = {
messageId: "message-id",
destinationId: "destination-id",
timeToLive: 2419200,
data: {
"key1": "value1",
"key2": "value2"
}
};
chrome.gcm.send(message, function(messageId) {});
};
{
"manifest_version": 2,
"name": "Test GCM App",
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzXCAvAUOKVNuBGWfaRY6QW1YSs+2EnmERkltllVyk9T6H/a7wkdBAKpvKsEbE9PtjmHrP/Jh/XFX1AdpTFAJ7KsQ55GdyTwUW7iB5HsR4NI6dXewK2ba+vDbtBLytR9msXFpvuVnAsEmLlHf9RGuxczvOEbGXcHkUw0AuzGu72wIDAQAB",
"version": "1.0",
"description": "Tests GCM API",
"background": {
"scripts": ["send_message_data.js"]
},
"permissions": ["gcm"]
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var message = {
messageId: "message-id",
destinationId: "destination-id",
timeToLive: 2419200,
data: {
"key1": "value1",
"key2": "value2"
}
};
chrome.test.runTests([
function testSend() {
chrome.gcm.send(message, function(messageId) {
chrome.test.succeed();
});
}
]);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment