on xenial help sign in
Add iconUrl test and fix bug uncovered by test
3ae2139Josh Arenson
plugins/LightDM/SessionsModel.cpp+8−2
@@ -63,11 +63,13 @@ QUrl SessionsModel::iconUrl(const QString sessionName) const
63 return QUrl(customIconUrl);
63 return QUrl(customIconUrl);
64 } else if (iconFile.exists()) {
64 } else if (iconFile.exists()) {
65 return QUrl(iconUrl);
65 return QUrl(iconUrl);
66− } else{
66+ } else {
67 // Search the legacy way
67 // Search the legacy way
68 QString path = searchDirectory.toString(QUrl::StripTrailingSlash) + "/";
68 QString path = searchDirectory.toString(QUrl::StripTrailingSlash) + "/";
69+ bool iconFound = false;
69 if (sessionName == "ubuntu" || sessionName == "ubuntu-2d") {
70 if (sessionName == "ubuntu" || sessionName == "ubuntu-2d") {
70 path += "ubuntu_badge.png";
71 path += "ubuntu_badge.png";
72+ iconFound = true;
71 } else if(
73 } else if(
72 sessionName == "gnome-classic" ||
74 sessionName == "gnome-classic" ||
73 sessionName == "gnome-flashback-compiz" ||
75 sessionName == "gnome-flashback-compiz" ||
@@ -77,15 +79,19 @@ QUrl SessionsModel::iconUrl(const QString sessionName) const
77 sessionName == "gnome"
79 sessionName == "gnome"
78 ){
80 ){
79 path += "gnome_badge.png";
81 path += "gnome_badge.png";
82+ iconFound = true;
80 } else if (sessionName == "plasma") {
83 } else if (sessionName == "plasma") {
81 path += "kde_badge.png";
84 path += "kde_badge.png";
85+ iconFound = true;
82 } else if (sessionName == "xterm") {
86 } else if (sessionName == "xterm") {
83 path += "recovery_console_badge.png";
87 path += "recovery_console_badge.png";
88+ iconFound = true;
84 } else if (sessionName == "remote-login") {
89 } else if (sessionName == "remote-login") {
85 path += "remote_login_help.png";
90 path += "remote_login_help.png";
91+ iconFound = true;
86 }
92 }
87
93
88− if (QFile(path).exists()) {
94+ if (QFile(path).exists() && iconFound) {
89 return path;
95 return path;
90 }
96 }
91 }
97 }
qml/Greeter/graphics/session_icons/plasma_badge.png → qml/Greeter/graphics/session_icons/kde_badge.pngrenamed

Binary file not shown.

tests/plugins/LightDM/IntegratedLightDM/sessionsmodel.cpp+32
@@ -59,6 +59,38 @@ private Q_SLOTS:
59 }
59 }
60 }
60 }
61
61
62+ void testIconLookupLogic()
63+ {
64+ const QString data[][2] = {
65+ //{SESSION KEY, ICON NAME}
66+ {"gnome-classic", "gnome_badge.png"},
67+ {"gnome-flashback-compiz", "gnome_badge.png"},
68+ {"gnome-flashback-metacity", "gnome_badge.png"},
69+ {"gnome-shell", "gnome_badge.png"},
70+ {"gnome-wayland", "gnome_badge.png"},
71+ {"gnome", "gnome_badge.png"},
72+ {"kde", "kde_badge.png"},
73+ {"plasma", "kde_badge.png"},
74+ {"recovery_console", "recovery_console_badge.png"},
75+ {"ubuntu","ubuntu_badge.png"},
76+ {"ubuntu-2d", "ubuntu_badge.png"},
77+ {"xterm", "recovery_console_badge.png"},
78+ {"made up session", "unknown_badge.png"},
79+ {"", "unknown_badge.png"}
80+ };
81+
82+ const short length = sizeof(data) / sizeof(data[0]);
83+ for (int i = 0; i < length; i++) {
84+ std::string key = data[i][0].toStdString();
85+ std::string icon = data[i][1].toStdString();
86+ std::string url = model->iconUrl(data[i][0]).toString().toStdString();
87+ std::string errorMessage = "Session icon url for " + key +
88+ " should contain " + icon + " but " + url + " was returned";
89+ QVERIFY2(model->iconUrl(data[i][0]).toString().contains(data[i][1]),
90+ errorMessage.c_str());
91+ }
92+ }
93+
62 void testMultipleSessionsCountIsCorrect()
94 void testMultipleSessionsCountIsCorrect()
63 {
95 {
64 sourceModel->setTestScenario("multipleSessions");
96 sourceModel->setTestScenario("multipleSessions");