| 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; | 597 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; |
| 598 function = new UpdateWindowFunction(); | 598 function = new UpdateWindowFunction(); |
| 599 function->set_extension(extension.get()); | 599 function->set_extension(extension.get()); |
| 600 EXPECT_TRUE(MatchPattern( | 600 EXPECT_TRUE(MatchPattern( |
| 601 utils::RunFunctionAndReturnError( | 601 utils::RunFunctionAndReturnError( |
| 602 function.get(), | 602 function.get(), |
| 603 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 603 base::StringPrintf(kArgsMaximizedWithBounds, window_id), |
| 604 browser()), | 604 browser()), |
| 605 keys::kInvalidWindowStateError)); | 605 keys::kInvalidWindowStateError)); |
| 606 } | 606 } |
| 607 |
| 608 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) { |
| 609 static const char kNewBlankTabArgs[] ="about:blank"; |
| 610 |
| 611 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(), |
| 612 NEW_FOREGROUND_TAB, |
| 613 content::PAGE_TRANSITION_LINK, false); |
| 614 content::WebContents* web_contents = browser()->OpenURL(params); |
| 615 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
| 616 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); |
| 617 int tab_index = -1; |
| 618 TabStripModel* tab_strip; |
| 619 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); |
| 620 |
| 621 scoped_refptr<DuplicateTabFunction> duplicate_tab_function( |
| 622 new DuplicateTabFunction()); |
| 623 scoped_ptr<base::DictionaryValue> test_extension_value( |
| 624 utils::ParseDictionary( |
| 625 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}" |
| 626 )); |
| 627 scoped_refptr<extensions::Extension> empty_tab_extension( |
| 628 utils::CreateExtension(test_extension_value.get())); |
| 629 duplicate_tab_function->set_extension(empty_tab_extension.get()); |
| 630 duplicate_tab_function->set_has_callback(true); |
| 631 |
| 632 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( |
| 633 utils::RunFunctionAndReturnSingleResult( |
| 634 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), |
| 635 browser()))); |
| 636 |
| 637 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); |
| 638 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(), |
| 639 "windowId"); |
| 640 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); |
| 641 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); |
| 642 // Duplicate tab id should be different from the original tab id. |
| 643 EXPECT_NE(tab_id, duplicate_tab_id); |
| 644 EXPECT_EQ(window_id, duplicate_tab_window_id); |
| 645 EXPECT_EQ(tab_index + 1, duplicate_tab_index); |
| 646 // The test empty tab extension has tabs permissions, therefore |
| 647 // |duplicate_result| should contain url, title, and faviconUrl |
| 648 // in the function result. |
| 649 EXPECT_TRUE(utils::HasPrivacySensitiveFields(duplicate_result.get())); |
| 650 } |
| 651 |
| 652 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTabNoPermission) { |
| 653 static const char kNewBlankTabArgs[] ="about:blank"; |
| 654 |
| 655 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(), |
| 656 NEW_FOREGROUND_TAB, |
| 657 content::PAGE_TRANSITION_LINK, false); |
| 658 content::WebContents* web_contents = browser()->OpenURL(params); |
| 659 int tab_id = ExtensionTabUtil::GetTabId(web_contents); |
| 660 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents); |
| 661 int tab_index = -1; |
| 662 TabStripModel* tab_strip; |
| 663 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index); |
| 664 |
| 665 scoped_refptr<DuplicateTabFunction> duplicate_tab_function( |
| 666 new DuplicateTabFunction()); |
| 667 scoped_refptr<extensions::Extension> empty_extension( |
| 668 utils::CreateEmptyExtension()); |
| 669 duplicate_tab_function->set_extension(empty_extension.get()); |
| 670 duplicate_tab_function->set_has_callback(true); |
| 671 |
| 672 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary( |
| 673 utils::RunFunctionAndReturnSingleResult( |
| 674 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id), |
| 675 browser()))); |
| 676 |
| 677 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id"); |
| 678 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(), |
| 679 "windowId"); |
| 680 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index"); |
| 681 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType()); |
| 682 // Duplicate tab id should be different from the original tab id. |
| 683 EXPECT_NE(tab_id, duplicate_tab_id); |
| 684 EXPECT_EQ(window_id, duplicate_tab_window_id); |
| 685 EXPECT_EQ(tab_index + 1, duplicate_tab_index); |
| 686 // The test empty extension has no permissions, therefore |duplicate_result| |
| 687 // should not contain url, title, and faviconUrl in the function result. |
| 688 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get())); |
| 689 } |
| OLD | NEW |