aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2018-01-31 16:28:07 +0100
committerMitch Curtis <mitch.curtis@qt.io>2018-02-05 15:14:48 +0000
commita5aa09dfd7e42f38545fe4640b0fa251bdd32be9 (patch)
tree64da9335dc93d496239767bf18a07a0e3ce8f8cb /tests
parentb9584b13d53f36da5585051346d03a86650961bc (diff)
Make AbstractButton's icon properties win over Action's when both are set
Task-number: QTBUG-65193 Change-Id: Idff23dcc35f3c3fe41406678613b022098149318 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/controls/data/tst_abstractbutton.qml221
1 files changed, 206 insertions, 15 deletions
diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml
index 7acf9882..a46a08df 100644
--- a/tests/auto/controls/data/tst_abstractbutton.qml
+++ b/tests/auto/controls/data/tst_abstractbutton.qml
@@ -285,6 +285,208 @@ TestCase {
compare(spy.count, data.resetChanged ? 1 : 0)
}
+ function test_actionIcon_data() {
+ var data = []
+
+ // Save duplicating the rows by reusing them with different properties of the same type.
+ // This means that the first loop will test icon.name and the second one will test icon.source.
+ var stringPropertyValueSuffixes = [
+ { propertyName: "name", valueSuffix: "IconName" },
+ { propertyName: "source", valueSuffix: "IconSource" }
+ ]
+
+ for (var i = 0; i < stringPropertyValueSuffixes.length; ++i) {
+ var propertyName = stringPropertyValueSuffixes[i].propertyName
+ var valueSuffix = stringPropertyValueSuffixes[i].valueSuffix
+
+ var buttonPropertyValue = "Button" + valueSuffix
+ var buttonPropertyValue2 = "Button" + valueSuffix + "2"
+ var actionPropertyValue = "Action" + valueSuffix
+ var actionPropertyValue2 = "Action" + valueSuffix + "2"
+
+ data.push({ tag: "implicit " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ resetExpected: "", resetChanged: true })
+ data.push({ tag: "explicit " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: actionPropertyValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ data.push({ tag: "empty button " + propertyName, property: propertyName,
+ initButton: "", initAction: actionPropertyValue,
+ assignExpected: "", assignChanged: false,
+ resetExpected: "", resetChanged: false })
+ data.push({ tag: "empty action " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: "",
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ data.push({ tag: "empty both " + propertyName, property: propertyName,
+ initButton: undefined, initAction: "",
+ assignExpected: "", assignChanged: false,
+ resetExpected: "", resetChanged: false })
+ data.push({ tag: "modify button " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ modifyButton: buttonPropertyValue2,
+ modifyButtonExpected: buttonPropertyValue2, modifyButtonChanged: true,
+ resetExpected: buttonPropertyValue2, resetChanged: false })
+ data.push({ tag: "modify implicit action " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ modifyAction: actionPropertyValue2,
+ modifyActionExpected: actionPropertyValue2, modifyActionChanged: true,
+ resetExpected: "", resetChanged: true })
+ data.push({ tag: "modify explicit action " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: actionPropertyValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ modifyAction: actionPropertyValue2,
+ modifyActionExpected: buttonPropertyValue, modifyActionChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ }
+
+ var intPropertyNames = [
+ "width",
+ "height",
+ ]
+
+ for (i = 0; i < intPropertyNames.length; ++i) {
+ propertyName = intPropertyNames[i]
+
+ buttonPropertyValue = 20
+ buttonPropertyValue2 = 21
+ actionPropertyValue = 40
+ actionPropertyValue2 = 41
+ var defaultValue = 0
+
+ data.push({ tag: "implicit " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ resetExpected: defaultValue, resetChanged: true })
+ data.push({ tag: "explicit " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: actionPropertyValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ data.push({ tag: "default button " + propertyName, property: propertyName,
+ initButton: defaultValue, initAction: actionPropertyValue,
+ assignExpected: defaultValue, assignChanged: false,
+ resetExpected: defaultValue, resetChanged: false })
+ data.push({ tag: "default action " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: defaultValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ data.push({ tag: "default both " + propertyName, property: propertyName,
+ initButton: undefined, initAction: defaultValue,
+ assignExpected: defaultValue, assignChanged: false,
+ resetExpected: defaultValue, resetChanged: false })
+ data.push({ tag: "modify button " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ modifyButton: buttonPropertyValue2,
+ modifyButtonExpected: buttonPropertyValue2, modifyButtonChanged: true,
+ resetExpected: buttonPropertyValue2, resetChanged: false })
+ data.push({ tag: "modify implicit action " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ modifyAction: actionPropertyValue2,
+ modifyActionExpected: actionPropertyValue2, modifyActionChanged: true,
+ resetExpected: defaultValue, resetChanged: true })
+ data.push({ tag: "modify explicit action " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: actionPropertyValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ modifyAction: actionPropertyValue2,
+ modifyActionExpected: buttonPropertyValue, modifyActionChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ }
+
+ propertyName = "color"
+ buttonPropertyValue = "#aa0000"
+ buttonPropertyValue2 = "#ff0000"
+ actionPropertyValue = "#0000aa"
+ actionPropertyValue2 = "#0000ff"
+ defaultValue = "#00000000"
+
+ data.push({ tag: "implicit " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ resetExpected: defaultValue, resetChanged: true })
+ data.push({ tag: "explicit " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: actionPropertyValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ data.push({ tag: "default button " + propertyName, property: propertyName,
+ initButton: defaultValue, initAction: actionPropertyValue,
+ assignExpected: defaultValue, assignChanged: false,
+ resetExpected: defaultValue, resetChanged: false })
+ data.push({ tag: "default action " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: defaultValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+ data.push({ tag: "default both " + propertyName, property: propertyName,
+ initButton: undefined, initAction: defaultValue,
+ assignExpected: defaultValue, assignChanged: false,
+ resetExpected: defaultValue, resetChanged: false })
+ data.push({ tag: "modify button " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ modifyButton: buttonPropertyValue2,
+ modifyButtonExpected: buttonPropertyValue2, modifyButtonChanged: true,
+ resetExpected: buttonPropertyValue2, resetChanged: false })
+ data.push({ tag: "modify implicit action " + propertyName, property: propertyName,
+ initButton: undefined, initAction: actionPropertyValue,
+ assignExpected: actionPropertyValue, assignChanged: true,
+ modifyAction: actionPropertyValue2,
+ modifyActionExpected: actionPropertyValue2, modifyActionChanged: true,
+ resetExpected: defaultValue, resetChanged: true })
+ data.push({ tag: "modify explicit action " + propertyName, property: propertyName,
+ initButton: buttonPropertyValue, initAction: actionPropertyValue,
+ assignExpected: buttonPropertyValue, assignChanged: false,
+ modifyAction: actionPropertyValue2,
+ modifyActionExpected: buttonPropertyValue, modifyActionChanged: false,
+ resetExpected: buttonPropertyValue, resetChanged: false })
+
+ return data;
+ }
+
+ function test_actionIcon(data) {
+ var control = createTemporaryObject(button, testCase)
+ verify(control)
+ control.icon[data.property] = data.initButton
+
+ var act = action.createObject(control)
+ act.icon[data.property] = data.initAction
+
+ var spy = signalSpy.createObject(control, {target: control, signalName: "iconChanged"})
+ verify(spy.valid)
+
+ // assign action
+ spy.clear()
+ control.action = act
+ compare(control.icon[data.property], data.assignExpected)
+ compare(spy.count, data.assignChanged ? 1 : 0)
+
+ // modify button
+ if (data.hasOwnProperty("modifyButton")) {
+ spy.clear()
+ control.icon[data.property] = data.modifyButton
+ compare(control.icon[data.property], data.modifyButtonExpected)
+ compare(spy.count, data.modifyButtonChanged ? 1 : 0)
+ }
+
+ // modify action
+ if (data.hasOwnProperty("modifyAction")) {
+ spy.clear()
+ act.icon[data.property] = data.modifyAction
+ compare(control.icon[data.property], data.modifyActionExpected)
+ compare(spy.count, data.modifyActionChanged ? 1 : 0)
+ }
+
+ // reset action
+ spy.clear()
+ control.action = null
+ compare(control.icon[data.property], data.resetExpected)
+ compare(spy.count, data.resetChanged ? 1 : 0)
+ }
+
Component {
id: actionButton
AbstractButton {
@@ -305,8 +507,6 @@ TestCase {
// initial values
compare(control.text, "Default")
- compare(control.icon.name, "default")
- compare(control.icon.source, "qrc:/icons/default.png")
compare(control.checkable, true)
compare(control.checked, true)
compare(control.enabled, false)
@@ -316,14 +516,10 @@ TestCase {
// changes via action
control.action.text = "Action"
- control.action.icon.name = "action"
- control.action.icon.source = "qrc:/icons/action.png"
control.action.checkable = false
control.action.checked = false
control.action.enabled = true
compare(control.text, "Action") // propagates
- compare(control.icon.name, "action") // propagates
- compare(control.icon.source, "qrc:/icons/action.png") // propagates
compare(control.checkable, false) // propagates
compare(control.checked, false) // propagates
compare(control.enabled, true) // propagates
@@ -331,31 +527,26 @@ TestCase {
// changes via button
control.text = "Button"
- control.icon.name = "button"
- control.icon.source = "qrc:/icons/button.png"
control.checkable = true
control.checked = true
control.enabled = false
compare(control.text, "Button")
- compare(control.icon.name, "button")
- compare(control.icon.source, "qrc:/icons/button.png")
compare(control.checkable, true)
compare(control.checked, true)
compare(control.enabled, false)
compare(control.action.text, "Action") // does NOT propagate
- compare(control.action.icon.name, "action") // does NOT propagate
- compare(control.action.icon.source, "qrc:/icons/action.png") // does NOT propagate
compare(control.action.checkable, true) // propagates
compare(control.action.checked, true) // propagates
compare(control.action.enabled, true) // does NOT propagate
compare(textSpy.count, 2)
- // remove the action so that only the button's text is left
+ // remove the action so that only the button's properties are left
control.action = null
compare(control.text, "Button")
compare(textSpy.count, 2)
- // setting an action while button has text shouldn't cause a change in the button's effective text
+ // setting an action while button has a particular property set
+ // shouldn't cause a change in the button's effective property value
var secondAction = createTemporaryObject(action, testCase)
verify(secondAction)
secondAction.text = "SecondAction"
@@ -363,7 +554,7 @@ TestCase {
compare(control.text, "Button")
compare(textSpy.count, 2)
- // test setting an action with empty text
+ // test setting an action whose properties aren't set
var thirdAction = createTemporaryObject(action, testCase)
verify(thirdAction)
control.action = thirdAction