Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/tabs/tabs.h" | 5 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 | 540 |
| 541 static const char kArgsMaximizedWithBounds[] = | 541 static const char kArgsMaximizedWithBounds[] = |
| 542 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; | 542 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; |
| 543 EXPECT_TRUE(MatchPattern( | 543 EXPECT_TRUE(MatchPattern( |
| 544 utils::RunFunctionAndReturnError( | 544 utils::RunFunctionAndReturnError( |
| 545 new UpdateWindowFunction(), | 545 new UpdateWindowFunction(), |
| 546 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 546 base::StringPrintf(kArgsMaximizedWithBounds, window_id), |
| 547 browser()), | 547 browser()), |
| 548 keys::kInvalidWindowStateError)); | 548 keys::kInvalidWindowStateError)); |
| 549 } | 549 } |
| 550 | |
| 551 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { | |
| 552 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); | |
| 553 // 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.
| |
| 554 create_tab_function->set_has_callback(true); | |
| 555 | |
| 556 static const char kNewBlankTabArgs[] = | |
| 557 "[{\"url\": \"about:blank\"}]"; | |
| 558 | |
| 559 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.
| |
| 560 utils::RunFunctionAndReturnResult( | |
| 561 create_tab_function.get(), | |
| 562 kNewBlankTabArgs, | |
| 563 browser()))); | |
| 564 | |
| 565 int tab_id = utils::GetInteger(result.get(), "id"); | |
| 566 int tab_index = utils::GetInteger(result.get(), "index"); | |
| 567 | |
| 568 scoped_refptr<DuplicateTabFunction> duplicate_tab_function( | |
| 569 new DuplicateTabFunction()); | |
| 570 scoped_ptr<base::DictionaryValue> test_extension_value( | |
| 571 utils::ParseDictionary( | |
| 572 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}" | |
| 573 )); | |
| 574 scoped_refptr<extensions::Extension> empty_tab_extension( | |
| 575 utils::CreateEmptyExtensionWithValue(test_extension_value.get())); | |
| 576 duplicate_tab_function->set_extension(empty_tab_extension.get()); | |
| 577 // Without a callback the function will not generate a result. | |
| 578 duplicate_tab_function->set_has_callback(true); | |
| 579 | |
| 580 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( | |
| 581 utils::RunFunctionAndReturnResult( | |
| 582 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), | |
| 583 browser()))); | |
| 584 | |
| 585 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); | |
| 586 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); | |
| 587 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); | |
| 588 // Duplicate tab id should be different from the original tab id. | |
| 589 EXPECT_NE(tab_id, duplicate_tab_id); | |
| 590 EXPECT_EQ(tab_index + 1, duplicate_tab_index); | |
| 591 // The test empty tab extension has tabs permissions, therefore | |
| 592 // |duplicate_result| should contain url, title, and faviconUrl | |
| 593 // in the function result. | |
| 594 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.
| |
| 595 } | |
| 596 | |
| 597 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTabNoPermission) { | |
| 598 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); | |
| 599 // Without a callback the function will not generate a result. | |
| 600 create_tab_function->set_has_callback(true); | |
| 601 | |
| 602 static const char kNewBlankTabArgs[] = | |
| 603 "[{\"url\": \"about:blank\"}]"; | |
| 604 | |
| 605 scoped_ptr<base::DictionaryValue> result(utils::ToDictionary( | |
| 606 utils::RunFunctionAndReturnResult( | |
| 607 create_tab_function.get(), | |
| 608 kNewBlankTabArgs, | |
| 609 browser()))); | |
| 610 | |
| 611 int tab_id = utils::GetInteger(result.get(), "id"); | |
| 612 int tab_index = utils::GetInteger(result.get(), "index"); | |
| 613 | |
| 614 scoped_refptr<DuplicateTabFunction> duplicate_tab_function( | |
| 615 new DuplicateTabFunction()); | |
| 616 scoped_refptr<extensions::Extension> empty_extension( | |
| 617 utils::CreateEmptyExtension()); | |
| 618 duplicate_tab_function->set_extension(empty_extension.get()); | |
| 619 // Without a callback the function will not generate a result. | |
| 620 duplicate_tab_function->set_has_callback(true); | |
| 621 | |
| 622 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( | |
| 623 utils::RunFunctionAndReturnResult( | |
| 624 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), | |
| 625 browser()))); | |
| 626 | |
| 627 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); | |
| 628 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); | |
| 629 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); | |
| 630 // Duplicate tab id should be different from the original tab id. | |
| 631 EXPECT_NE(tab_id, duplicate_tab_id); | |
| 632 EXPECT_EQ(tab_index + 1, duplicate_tab_index); | |
| 633 // The test empty extension has no permissions, therefore |duplicate_result| | |
| 634 // should not contain url, title, and faviconUrl in the function result. | |
| 635 EXPECT_FALSE(utils::HasPrivateInfo(duplicate_result.get())); | |
| 636 } | |
| OLD | NEW |