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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a | 78 // TODO(aa): Can't assume window is focused. On mac, calling Activate() from a |
79 // browser test doesn't seem to do anything, so can't test the opposite | 79 // browser test doesn't seem to do anything, so can't test the opposite |
80 // either. | 80 // either. |
81 EXPECT_EQ(browser()->window()->IsActive(), | 81 EXPECT_EQ(browser()->window()->IsActive(), |
82 utils::GetBoolean(result.get(), "focused")); | 82 utils::GetBoolean(result.get(), "focused")); |
83 | 83 |
84 // TODO(aa): Minimized and maximized dimensions. Is there a way to set | 84 // TODO(aa): Minimized and maximized dimensions. Is there a way to set |
85 // minimize/maximize programmatically? | 85 // minimize/maximize programmatically? |
86 | 86 |
87 // Popup. | 87 // Popup. |
88 Browser* popup_browser = Browser::CreateWithParams( | 88 Browser* popup_browser = new Browser( |
89 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); | 89 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); |
90 result.reset(utils::ToDictionary( | 90 result.reset(utils::ToDictionary( |
91 utils::RunFunctionAndReturnSingleResult( | 91 utils::RunFunctionAndReturnSingleResult( |
92 new GetWindowFunction(), | 92 new GetWindowFunction(), |
93 base::StringPrintf( | 93 base::StringPrintf( |
94 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)), | 94 "[%u]", ExtensionTabUtil::GetWindowId(popup_browser)), |
95 browser()))); | 95 browser()))); |
96 EXPECT_EQ("popup", utils::GetString(result.get(), "type")); | 96 EXPECT_EQ("popup", utils::GetString(result.get(), "type")); |
97 | 97 |
98 // Panel. | 98 // Panel. |
99 Browser* panel_browser = Browser::CreateWithParams( | 99 Browser* panel_browser = new Browser( |
100 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile())); | 100 Browser::CreateParams(Browser::TYPE_PANEL, browser()->profile())); |
101 result.reset(utils::ToDictionary( | 101 result.reset(utils::ToDictionary( |
102 utils::RunFunctionAndReturnSingleResult( | 102 utils::RunFunctionAndReturnSingleResult( |
103 new GetWindowFunction(), | 103 new GetWindowFunction(), |
104 base::StringPrintf( | 104 base::StringPrintf( |
105 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)), | 105 "[%u]", ExtensionTabUtil::GetWindowId(panel_browser)), |
106 browser()))); | 106 browser()))); |
107 EXPECT_EQ("panel", utils::GetString(result.get(), "type")); | 107 EXPECT_EQ("panel", utils::GetString(result.get(), "type")); |
108 | 108 |
109 // Incognito. | 109 // Incognito. |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); | 482 EXPECT_TRUE(result_tabs->GetDictionary(i, &result_tab)); |
483 EXPECT_NE(focused_window_id, utils::GetInteger(result_tab, | 483 EXPECT_NE(focused_window_id, utils::GetInteger(result_tab, |
484 keys::kWindowIdKey)); | 484 keys::kWindowIdKey)); |
485 } | 485 } |
486 } | 486 } |
487 | 487 |
488 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { | 488 IN_PROC_BROWSER_TEST_F(ExtensionTabsTest, DontCreateTabInClosingPopupWindow) { |
489 // Test creates new popup window, closes it right away and then tries to open | 489 // Test creates new popup window, closes it right away and then tries to open |
490 // a new tab in it. Tab should not be opened in the popup window, but in a | 490 // a new tab in it. Tab should not be opened in the popup window, but in a |
491 // tabbed browser window. | 491 // tabbed browser window. |
492 Browser* popup_browser = Browser::CreateWithParams( | 492 Browser* popup_browser = new Browser( |
493 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); | 493 Browser::CreateParams(Browser::TYPE_POPUP, browser()->profile())); |
494 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); | 494 int window_id = ExtensionTabUtil::GetWindowId(popup_browser); |
495 chrome::CloseWindow(popup_browser); | 495 chrome::CloseWindow(popup_browser); |
496 | 496 |
497 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); | 497 scoped_refptr<CreateTabFunction> create_tab_function(new CreateTabFunction()); |
498 // Without a callback the function will not generate a result. | 498 // Without a callback the function will not generate a result. |
499 create_tab_function->set_has_callback(true); | 499 create_tab_function->set_has_callback(true); |
500 | 500 |
501 static const char kNewBlankTabArgs[] = | 501 static const char kNewBlankTabArgs[] = |
502 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; | 502 "[{\"url\": \"about:blank\", \"windowId\": %u}]"; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 | 542 |
543 static const char kArgsMaximizedWithBounds[] = | 543 static const char kArgsMaximizedWithBounds[] = |
544 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; | 544 "[%u, {\"state\": \"maximized\", \"width\": 500}]"; |
545 EXPECT_TRUE(MatchPattern( | 545 EXPECT_TRUE(MatchPattern( |
546 utils::RunFunctionAndReturnError( | 546 utils::RunFunctionAndReturnError( |
547 new UpdateWindowFunction(), | 547 new UpdateWindowFunction(), |
548 base::StringPrintf(kArgsMaximizedWithBounds, window_id), | 548 base::StringPrintf(kArgsMaximizedWithBounds, window_id), |
549 browser()), | 549 browser()), |
550 keys::kInvalidWindowStateError)); | 550 keys::kInvalidWindowStateError)); |
551 } | 551 } |
OLD | NEW |