This source file includes following definitions.
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part_chromeos.h"
#include "chrome/browser/chromeos/memory/oom_priority_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/test/test_utils.h"
#include "url/gurl.h"
using content::OpenURLParams;
namespace {
typedef InProcessBrowserTest OomPriorityManagerTest;
IN_PROC_BROWSER_TEST_F(OomPriorityManagerTest, OomPriorityManagerBasics) {
using content::WindowedNotificationObserver;
chromeos::OomPriorityManager* oom_priority_manager =
g_browser_process->platform_part()->oom_priority_manager();
EXPECT_FALSE(oom_priority_manager->recent_tab_discard());
WindowedNotificationObserver load1(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false);
browser()->OpenURL(open1);
load1.Wait();
WindowedNotificationObserver load2(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
false);
browser()->OpenURL(open2);
load2.Wait();
WindowedNotificationObserver load3(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open3(GURL(chrome::kChromeUITermsURL), content::Referrer(),
NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED,
false);
browser()->OpenURL(open3);
load3.Wait();
EXPECT_EQ(3, browser()->tab_strip_model()->count());
WindowedNotificationObserver load4(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open4(GURL(chrome::kChromeUIVersionURL), content::Referrer(),
CURRENT_TAB, content::PAGE_TRANSITION_TYPED,
false);
browser()->OpenURL(open4);
load4.Wait();
WindowedNotificationObserver load5(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
OpenURLParams open5(GURL("chrome://dns"), content::Referrer(),
CURRENT_TAB, content::PAGE_TRANSITION_TYPED,
false);
browser()->OpenURL(open5);
load5.Wait();
EXPECT_EQ(3, browser()->tab_strip_model()->count());
EXPECT_TRUE(oom_priority_manager->DiscardTab());
EXPECT_EQ(3, browser()->tab_strip_model()->count());
EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0));
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
EXPECT_TRUE(oom_priority_manager->recent_tab_discard());
EXPECT_TRUE(oom_priority_manager->DiscardTab());
EXPECT_EQ(3, browser()->tab_strip_model()->count());
EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0));
EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1));
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
EXPECT_FALSE(oom_priority_manager->DiscardTab());
EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(0));
EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(1));
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
browser()->tab_strip_model()->ActivateTabAt(1, true);
EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
browser()->tab_strip_model()->DiscardWebContentsAt(2);
EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2));
browser()->GetFindBarController();
WindowedNotificationObserver reload1(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
chrome::SelectNumberedTab(browser(), 0);
reload1.Wait();
EXPECT_EQ(browser()->GetFindBarController()->web_contents(),
browser()->tab_strip_model()->GetActiveWebContents());
EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0));
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
EXPECT_TRUE(browser()->tab_strip_model()->IsTabDiscarded(2));
WindowedNotificationObserver reload2(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
chrome::SelectNumberedTab(browser(), 2);
reload2.Wait();
EXPECT_EQ(2, browser()->tab_strip_model()->active_index());
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(0));
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(1));
EXPECT_FALSE(browser()->tab_strip_model()->IsTabDiscarded(2));
EXPECT_TRUE(chrome::CanGoBack(browser()));
EXPECT_FALSE(chrome::CanGoForward(browser()));
WindowedNotificationObserver back1(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
chrome::GoBack(browser(), CURRENT_TAB);
back1.Wait();
EXPECT_TRUE(chrome::CanGoBack(browser()));
EXPECT_TRUE(chrome::CanGoForward(browser()));
WindowedNotificationObserver back2(
content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
chrome::GoBack(browser(), CURRENT_TAB);
back2.Wait();
EXPECT_FALSE(chrome::CanGoBack(browser()));
EXPECT_TRUE(chrome::CanGoForward(browser()));
}
}