Repository navigation
Expand file tree
/
Copy pathAddressBarTest.cpp
More file actions
130 lines (105 loc) · 4.25 KB
/
Copy pathAddressBarTest.cpp
File metadata and controls
130 lines (105 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (C) Explorer++ Project
// SPDX-License-Identifier: GPL-3.0-only
// See LICENSE in the top level directory
#include "pch.h"
#include "AddressBar.h"
#include "AddressBarView.h"
#include "BrowserTestBase.h"
#include "BrowserWindowFake.h"
#include "PidlTestHelper.h"
#include "ShellBrowser/ShellBrowser.h"
#include "ShellBrowser/ShellNavigationController.h"
#include "Tab.h"
#include <gtest/gtest.h>
using namespace testing;
class AddressBarTest : public BrowserTestBase
{
protected:
AddressBarTest() :
m_browser(AddBrowser()),
m_addressBarView(AddressBarView::Create(m_browser->GetHWND(), &m_config)),
m_addressBar(AddressBar::Create(m_addressBarView, m_browser, &m_tabEvents,
&m_shellBrowserEvents, &m_navigationEvents, &m_runtime, &m_iconFetcher))
{
}
void DestroyAddressBar()
{
// The lifetime of the AddressBar instance is tied to the lifetime of the view. So, this
// will destroy both instances.
m_addressBarView->DestroyForTesting();
m_addressBarView = nullptr;
m_addressBar = nullptr;
}
BrowserWindowFake *const m_browser;
AddressBarView *m_addressBarView = nullptr;
AddressBar *m_addressBar = nullptr;
};
TEST_F(AddressBarTest, DisplayUpdateAfterNavigation)
{
auto *tab1 = m_browser->AddTab(L"c:\\");
auto *tab2 = m_browser->AddTab(L"c:\\");
auto *browser2 = AddBrowser();
auto *tab3 = browser2->AddTab(L"c:\\");
std::wstring path = L"c:\\path\\to\\folder";
NavigateTab(tab1, path);
EXPECT_THAT(m_addressBarView->GetText(), StrCaseEq(path));
// tab2 isn't active, so navigations in it should be ignored by the address bar. The path shown
// should still be the original path.
NavigateTab(tab2, L"d:\\");
EXPECT_THAT(m_addressBarView->GetText(), StrCaseEq(path));
// tab3 is in a different browser window, so navigations in it should also be ignored.
NavigateTab(tab3, L"e:\\");
EXPECT_THAT(m_addressBarView->GetText(), StrCaseEq(path));
}
TEST_F(AddressBarTest, DisplayUpdateAfterTabSwitch)
{
std::wstring path1 = L"c:\\path1";
m_browser->AddTab(path1);
std::wstring path2 = L"c:\\path2";
m_browser->AddTab(path2);
EXPECT_THAT(m_addressBarView->GetText(), StrCaseEq(path1));
m_browser->GetActiveTabContainer()->SelectTabAtIndex(1);
EXPECT_THAT(m_addressBarView->GetText(), StrCaseEq(path2));
}
TEST_F(AddressBarTest, OpenItemOnEnter)
{
auto *tab1 = m_browser->AddTab(L"c:\\original\\path");
std::wstring updatedPath = L"c:\\updated\\path";
m_addressBarView->SetTextForTesting(updatedPath);
auto *delegate = m_addressBarView->GetDelegateForTesting();
delegate->OnKeyPressed(VK_RETURN);
// The key press above should have resulted in a navigation in the active tab.
EXPECT_EQ(tab1->GetShellBrowser()->GetNavigationController()->GetNumHistoryEntries(), 2);
auto *currentEntry = tab1->GetShellBrowser()->GetNavigationController()->GetCurrentEntry();
ASSERT_NE(currentEntry, nullptr);
EXPECT_EQ(currentEntry->GetPidl(), CreateSimplePidlForTest(updatedPath));
}
TEST_F(AddressBarTest, RevertTextOnEscape)
{
std::wstring path = L"c:\\path";
m_browser->AddTab(path);
m_addressBarView->SetTextForTesting(L"c:\\path\\to\\second\\folder");
// This should result in the text being reverted back to the original text.
auto *delegate = m_addressBarView->GetDelegateForTesting();
delegate->OnKeyPressed(VK_ESCAPE);
EXPECT_THAT(m_addressBarView->GetText(), StrCaseEq(path));
}
TEST_F(AddressBarTest, ActiveTargetOnFocus)
{
auto *commandTargetManager = m_browser->GetCommandTargetManager();
EXPECT_NE(commandTargetManager->GetCurrentTarget(), m_addressBar);
// When the address bar receives focus, it should mark itself as the active target.
auto *delegate = m_addressBarView->GetDelegateForTesting();
delegate->OnFocused();
EXPECT_EQ(commandTargetManager->GetCurrentTarget(), m_addressBar);
}
TEST_F(AddressBarTest, IconRetrievalAfterDestruction)
{
// Doing this will cause the address bar to queue at least one icon retrieval task.
m_browser->AddTab(L"c:\\");
EXPECT_TRUE(m_iconFetcher.HasPendingRequests());
DestroyAddressBar();
// This will cause the pending icon retrieval task(s) to return. This should be safe, even
// though the address bar has been destroyed.
m_iconFetcher.CompletePendingRequests();
}