Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_test.cc

Issue 10697017: Tabs Extension: Implementation of tabs.duplicate api. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 static const char kArgsMaximizedWithBounds[] = 557 static const char kArgsMaximizedWithBounds[] =
558 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; 558 "[%u, {\"state\": \"maximized\", \"width\": 500}]";
559 function = new UpdateWindowFunction(); 559 function = new UpdateWindowFunction();
560 EXPECT_TRUE(MatchPattern( 560 EXPECT_TRUE(MatchPattern(
561 utils::RunFunctionAndReturnError( 561 utils::RunFunctionAndReturnError(
562 function.get(), 562 function.get(),
563 base::StringPrintf(kArgsMaximizedWithBounds, window_id), 563 base::StringPrintf(kArgsMaximizedWithBounds, window_id),
564 browser()), 564 browser()),
565 keys::kInvalidWindowStateError)); 565 keys::kInvalidWindowStateError));
566 } 566 }
567
568 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTab) {
569 static const char kNewBlankTabArgs[] ="about:blank";
570
571 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(),
572 NEW_FOREGROUND_TAB,
573 content::PAGE_TRANSITION_LINK, false);
574 content::WebContents* web_contents = browser()->OpenURL(params);
575 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
576 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
577 int tab_index = -1;
578 TabStripModel* tab_strip;
579 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
580
581 scoped_refptr<DuplicateTabFunction> duplicate_tab_function(
582 new DuplicateTabFunction());
583 scoped_ptr<base::DictionaryValue> test_extension_value(
584 utils::ParseDictionary(
585 "{\"name\": \"Test\", \"version\": \"1.0\", \"permissions\": [\"tabs\"]}"
586 ));
587 scoped_refptr<extensions::Extension> empty_tab_extension(
588 utils::CreateExtension(test_extension_value.get()));
589 duplicate_tab_function->set_extension(empty_tab_extension.get());
590 duplicate_tab_function->set_has_callback(true);
591
592 scoped_ptr<base::DictionaryValue> duplicate_result(utils::ToDictionary(
593 utils::RunFunctionAndReturnSingleResult(
594 duplicate_tab_function.get(), base::StringPrintf("[%u]", tab_id),
595 browser())));
596
597 int duplicate_tab_id = utils::GetInteger(duplicate_result.get(), "id");
598 int duplicate_tab_window_id = utils::GetInteger(duplicate_result.get(),
599 "windowId");
600 int duplicate_tab_index = utils::GetInteger(duplicate_result.get(), "index");
601 EXPECT_EQ(base::Value::TYPE_DICTIONARY, duplicate_result->GetType());
602 // Duplicate tab id should be different from the original tab id.
603 EXPECT_NE(tab_id, duplicate_tab_id);
604 EXPECT_EQ(window_id, duplicate_tab_window_id);
605 EXPECT_EQ(tab_index + 1, duplicate_tab_index);
606 // The test empty tab extension has tabs permissions, therefore
607 // |duplicate_result| should contain url, title, and faviconUrl
608 // in the function result.
609 EXPECT_TRUE(utils::HasPrivacySensitiveFields(duplicate_result.get()));
610 }
611
612 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DuplicateTabNoPermission) {
613 static const char kNewBlankTabArgs[] ="about:blank";
614
615 content::OpenURLParams params(GURL(kNewBlankTabArgs), content::Referrer(),
616 NEW_FOREGROUND_TAB,
617 content::PAGE_TRANSITION_LINK, false);
618 content::WebContents* web_contents = browser()->OpenURL(params);
619 int tab_id = ExtensionTabUtil::GetTabId(web_contents);
620 int window_id = ExtensionTabUtil::GetWindowIdOfTab(web_contents);
621 int tab_index = -1;
622 TabStripModel* tab_strip;
623 ExtensionTabUtil::GetTabStripModel(web_contents, &tab_strip, &tab_index);
624
625 scoped_refptr<DuplicateTabFunction> duplicate_tab_function(
626 new DuplicateTabFunction());
627 scoped_refptr<extensions::Extension> empty_extension(
628 utils::CreateEmptyExtension());
629 duplicate_tab_function->set_extension(empty_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 extension has no permissions, therefore |duplicate_result|
647 // should not contain url, title, and faviconUrl in the function result.
648 EXPECT_FALSE(utils::HasPrivacySensitiveFields(duplicate_result.get()));
649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698