Skip to content

Commit

Permalink
test: add test for level persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 22, 2021
1 parent bf37970 commit fd6b251
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
19 changes: 9 additions & 10 deletions shell/browser/api/electron_api_base_window.cc
Expand Up @@ -563,10 +563,6 @@ std::string BaseWindow::GetAlwaysOnTopLevel() {
return window_->GetAlwaysOnTopLevel();
}

int BaseWindow::GetZOrderLevel() {
return static_cast<int>(window_->GetZOrderLevel());
}

void BaseWindow::Center() {
window_->Center();
}
Expand Down Expand Up @@ -1234,8 +1230,6 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isClosable", &BaseWindow::IsClosable)
.SetMethod("setAlwaysOnTop", &BaseWindow::SetAlwaysOnTop)
.SetMethod("isAlwaysOnTop", &BaseWindow::IsAlwaysOnTop)
.SetMethod("getAlwaysOnTopLevel", &BaseWindow::GetAlwaysOnTopLevel)
.SetMethod("getZOrderLevel", &BaseWindow::GetZOrderLevel)
.SetMethod("center", &BaseWindow::Center)
.SetMethod("setPosition", &BaseWindow::SetPosition)
.SetMethod("getPosition", &BaseWindow::GetPosition)
Expand Down Expand Up @@ -1280,16 +1274,21 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
&BaseWindow::SetVisibleOnAllWorkspaces)
.SetMethod("isVisibleOnAllWorkspaces",
&BaseWindow::IsVisibleOnAllWorkspaces)
.SetMethod("setVibrancy", &BaseWindow::SetVibrancy)
.SetMethod("_setTouchBarItems", &BaseWindow::SetTouchBar)
.SetMethod("_refreshTouchBarItem", &BaseWindow::RefreshTouchBarItem)
.SetMethod("_setEscapeTouchBarItem", &BaseWindow::SetEscapeTouchBarItem)
#if defined(OS_MAC)
.SetMethod("getAlwaysOnTopLevel", &BaseWindow::GetAlwaysOnTopLevel)
.SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor)
#endif
.SetMethod("setVibrancy", &BaseWindow::SetVibrancy)
#if defined(OS_MAC)
.SetMethod("setTrafficLightPosition",
&BaseWindow::SetTrafficLightPosition)
.SetMethod("getTrafficLightPosition",
&BaseWindow::GetTrafficLightPosition)
#endif
.SetMethod("_setTouchBarItems", &BaseWindow::SetTouchBar)
.SetMethod("_refreshTouchBarItem", &BaseWindow::RefreshTouchBarItem)
.SetMethod("_setEscapeTouchBarItem", &BaseWindow::SetEscapeTouchBarItem)
#if defined(OS_MAC)
.SetMethod("selectPreviousTab", &BaseWindow::SelectPreviousTab)
.SetMethod("selectNextTab", &BaseWindow::SelectNextTab)
.SetMethod("mergeAllWindows", &BaseWindow::MergeAllWindows)
Expand Down
1 change: 0 additions & 1 deletion shell/browser/api/electron_api_base_window.h
Expand Up @@ -143,7 +143,6 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
void SetAlwaysOnTop(bool top, gin_helper::Arguments* args);
bool IsAlwaysOnTop();
std::string GetAlwaysOnTopLevel();
int GetZOrderLevel();
void Center();
void SetPosition(int x, int y, gin_helper::Arguments* args);
std::vector<int> GetPosition();
Expand Down
17 changes: 12 additions & 5 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -1430,15 +1430,12 @@ describe('BrowserWindow module', () => {
describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => {
let w = null as unknown as BrowserWindow;

afterEach(closeAllWindows);

beforeEach(() => {
w = new BrowserWindow({ show: true });
});

afterEach(async () => {
await closeWindow(w);
w = null as unknown as BrowserWindow;
});

it('sets the window as always on top', () => {
expect(w.isAlwaysOnTop()).to.be.false('is alwaysOnTop');
w.setAlwaysOnTop(true, 'screen-saver');
Expand Down Expand Up @@ -1466,6 +1463,16 @@ describe('BrowserWindow module', () => {
const [, alwaysOnTop] = await alwaysOnTopChanged;
expect(alwaysOnTop).to.be.true('is not alwaysOnTop');
});

ifit(process.platform === 'darwin')('honors the alwaysOnTop level of a child window', () => {
w = new BrowserWindow({ show: false });
const c = new BrowserWindow({ parent: w });
c.setAlwaysOnTop(true, 'screen-saver');

expect(w.isAlwaysOnTop()).to.be.false();
expect(c.isAlwaysOnTop()).to.be.true('child is not always on top');
expect((c as any).getAlwaysOnTopLevel()).to.equal('screen-saver');
});
});

describe('preconnect feature', () => {
Expand Down

0 comments on commit fd6b251

Please sign in to comment.