Chromium Code Reviews| Index: chrome/browser/extensions/api/tabs/tabs_test.cc |
| =================================================================== |
| --- chrome/browser/extensions/api/tabs/tabs_test.cc (revision 142698) |
| +++ chrome/browser/extensions/api/tabs/tabs_test.cc (working copy) |
| @@ -547,3 +547,90 @@ |
| browser()), |
| keys::kInvalidWindowStateError)); |
| } |
| + |
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { |
| + scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); |
| + // Without a callback the function will not generate a result. |
|
Aaron Boodman
2012/08/07 01:03:25
Don't need to copy this comment.
SanjoyPal
2012/08/14 11:14:13
Done.
|
| + create_tab_function->set_has_callback(true); |
| + |
| + static const char kNewBlankTabArgs[] = |
| + "[{\"url\": \"about:blank\"}]"; |
| + |
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
|
Aaron Boodman
2012/08/07 01:03:25
There's not really any need to use the extension A
SanjoyPal
2012/08/14 11:14:13
Done.
|
| + utils::RunFunctionAndReturnResult( |
| + create_tab_function.get(), |
| + kNewBlankTabArgs, |
| + browser()))); |
| + |
| + int tab_id = utils::GetInteger(result.get(), "id"); |
| + int tab_index = utils::GetInteger(result.get(), "index"); |
| + |
| + scoped_refptr<DuplicateTabFunction> duplicate_tab_function( |
| + new DuplicateTabFunction()); |
| + scoped_ptr<base::DictionaryValue> test_extension_value( |
| + utils::ParseDictionary( |
| + "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}" |
| + )); |
| + scoped_refptr<extensions::Extension> empty_tab_extension( |
| + utils::CreateEmptyExtensionWithValue(test_extension_value.get())); |
| + duplicate_tab_function->set_extension(empty_tab_extension.get()); |
| + // Without a callback the function will not generate a result. |
| + duplicate_tab_function->set_has_callback(true); |
| + |
| + scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( |
| + utils::RunFunctionAndReturnResult( |
| + duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), |
| + browser()))); |
| + |
| + int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); |
| + int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); |
| + EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); |
| + // Duplicate tab id should be different from the original tab id. |
| + EXPECT_NE(tab_id, duplicate_tab_id); |
| + EXPECT_EQ(tab_index + 1, duplicate_tab_index); |
| + // The test empty tab extension has tabs permissions, therefore |
| + // |duplicate_result| should contain url, title, and faviconUrl |
| + // in the function result. |
| + EXPECT_TRUE(utils::HasPrivateInfo(duplicate_result.get())); |
|
Aaron Boodman
2012/08/07 01:03:25
You could also test that the resulting tab is cont
SanjoyPal
2012/08/14 11:14:13
Done.
|
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTabNoPermission) { |
| + scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); |
| + // Without a callback the function will not generate a result. |
| + create_tab_function->set_has_callback(true); |
| + |
| + static const char kNewBlankTabArgs[] = |
| + "[{\"url\": \"about:blank\"}]"; |
| + |
| + scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( |
| + utils::RunFunctionAndReturnResult( |
| + create_tab_function.get(), |
| + kNewBlankTabArgs, |
| + browser()))); |
| + |
| + int tab_id = utils::GetInteger(result.get(), "id"); |
| + int tab_index = utils::GetInteger(result.get(), "index"); |
| + |
| + scoped_refptr<DuplicateTabFunction> duplicate_tab_function( |
| + new DuplicateTabFunction()); |
| + scoped_refptr<extensions::Extension> empty_extension( |
| + utils::CreateEmptyExtension()); |
| + duplicate_tab_function->set_extension(empty_extension.get()); |
| + // Without a callback the function will not generate a result. |
| + duplicate_tab_function->set_has_callback(true); |
| + |
| + scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( |
| + utils::RunFunctionAndReturnResult( |
| + duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), |
| + browser()))); |
| + |
| + int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); |
| + int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); |
| + EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); |
| + // Duplicate tab id should be different from the original tab id. |
| + EXPECT_NE(tab_id, duplicate_tab_id); |
| + EXPECT_EQ(tab_index + 1, duplicate_tab_index); |
| + // The test empty extension has no permissions, therefore |duplicate_result| |
| + // should not contain url, title, and faviconUrl in the function result. |
| + EXPECT_FALSE(utils::HasPrivateInfo(duplicate_result.get())); |
| +} |